<filename>qr_data_tables.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
QR Code helper tables

The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED
http://www.denso-wave.com/qrcode/faqpatent-e.html
"""

# alignment pattern locations
alignment_pattern_locations = [
    [6, 18],
    [6, 22],
    [6, 26],
    [6, 30],
    [6, 34],
    [6, 22, 38],
    [6, 24, 42],
    [6, 26, 46],
    [6, 28, 50],
    [6, 30, 54],
    [6, 32, 58],
    [6, 34, 62],
    [6, 26, 46, 66],
    [6, 26, 48, 70],
    [6, 26, 50, 74],
    [6, 30, 54, 78],
    [6, 30, 56, 82],
    [6, 30, 58, 86],
    [6, 34, 62, 90],
    [6, 28, 50, 72, 94],
    [6, 26, 50, 74, 98],
    [6, 30, 54, 78, 102],
    [6, 28, 54, 80, 106],
    [6, 32, 58, 84, 110],
    [6, 30, 58, 86, 114],
    [6, 34, 62, 90, 118],
    [6, 26, 50, 74, 98, 122],
    [6, 30, 54, 78, 102, 126],
    [6, 26, 52, 78, 104, 130],
    [6, 30, 56, 82, 108, 134],
    [6, 34, 60, 86, 112, 138],
    [6, 30, 58, 86, 114, 142],
    [6, 34, 62, 90, 118, 146],
    [6, 30, 54, 78, 102, 126, 150],
    [6, 24, 50, 76, 102, 128, 154],
    [6, 28, 54, 80, 106, 132, 158],
    [6, 32, 58, 84, 110, 136, 162],
    [6, 26, 54, 82, 110, 138, 166],
    [6, 30, 58, 86, 114, 142, 170],
]

# error correction levels
error_correction_levels = {
    'L': 1,
    'M': 0,
    'Q': 3,
    'H': 2,
}

# encoding modes
modes = {
    'numeric': 0b0001,
    'alphanumeric': 0b0010,
    'byte': 0b0100,
    'kanji': 0b1000,
    'ECI': 0b0111,
}

# terminator sizes
term_sizes = {
    'all': 4,
    'M1': 3,
    'M2': 5,
    'M3': 7,
    'M4': 9,
}

# used for alphanumeric mode
alphanumeric_table = {
    '0': 0,
    '1': 1,
    '2': 2,
    '3': 3,
    '4': 4,
    '5': 5,
    '6': 6,
    '7': 7,
    '8': 8,
    '9': 9,
    'A': 10,
    'B': 11,
    'C': 12,
    'D': 13,
    'E': 14,
    'F': 15,
    'G': 16,
    'H': 17,
    'I': 18,
    'J': 19,
    'K': 20,
    'L': 21,
    'M': 22,
    'N': 23,
    'O': 24,
    'P': 25,
    'Q': 26,
    'R': 27,
    'S': 28,
    'T': 29,
    'U': 30,
    'V': 31,
    'W': 32,
    'X': 33,
    'Y': 34,
    'Z': 35,
    ' ': 36,
    '$': 37,
    '%': 38,
    '*': 39,
    '+': 40,
    '-': 41,
    '.': 42,
    '/': 43,
    ':': 44,
}

# QR character capacities by version, error correction level and mode
capacity = {
    1: {
        'L': {'bits': 152, 'numeric': 41, 'alphanumeric': 25, 'byte': 17, 'kanji': 10},
        'M': {'bits': 128, 'numeric': 34, 'alphanumeric': 20, 'byte': 14, 'kanji': 8},
        'Q': {'bits': 104, 'numeric': 27, 'alphanumeric': 16, 'byte': 11, 'kanji': 7},
        'H': {'bits': 72, 'numeric': 17, 'alphanumeric': 10, 'byte': 7, 'kanji': 4},
    },
    2: {
        'L': {'bits': 272, 'numeric': 77, 'alphanumeric': 47, 'byte': 32, 'kanji': 20},
        'M': {'bits': 224, 'numeric': 63, 'alphanumeric': 38, 'byte': 26, 'kanji': 16},
        'Q': {'bits': 176, 'numeric': 48, 'alphanumeric': 29, 'byte': 20, 'kanji': 12},
        'H': {'bits': 128, 'numeric': 34, 'alphanumeric': 20, 'byte': 14, 'kanji': 8},
    },
    3: {
        'L': {'bits': 440, 'numeric': 127, 'alphanumeric': 77, 'byte': 53, 'kanji': 32},
        'M': {'bits': 352, 'numeric': 101, 'alphanumeric': 61, 'byte': 42, 'kanji': 26},
        'Q': {'bits': 272, 'numeric': 77, 'alphanumeric': 47, 'byte': 32, 'kanji': 20},
        'H': {'bits': 208, 'numeric': 58, 'alphanumeric': 35, 'byte': 24, 'kanji': 15},
    },
    4: {
        'L': {'bits': 640, 'numeric': 187, 'alphanumeric': 114, 'byte': 78, 'kanji': 48},
        'M': {'bits': 512, 'numeric': 149, 'alphanumeric': 90, 'byte': 62, 'kanji': 38},
        'Q': {'bits': 384, 'numeric': 111, 'alphanumeric': 67, 'byte': 46, 'kanji': 28},
        'H': {'bits': 288, 'numeric': 82, 'alphanumeric': 50, 'byte': 34, 'kanji': 21},
    },
    5: {
        'L': {'bits': 864, 'numeric': 255, 'alphanumeric': 154, 'byte': 106, 'kanji': 65},
        'M': {'bits': 688, 'numeric': 202, 'alphanumeric': 122, 'byte': 84, 'kanji': 52},
        'Q': {'bits': 496, 'numeric': 144, 'alphanumeric': 87, 'byte': 60, 'kanji': 37},
        'H': {'bits': 368, 'numeric': 106, 'alphanumeric': 64, 'byte': 44, 'kanji': 27},
    },
    6: {
        'L': {'bits': 1088, 'numeric': 322, 'alphanumeric': 195, 'byte': 134, 'kanji': 82},
        'M': {'bits': 864, 'numeric': 255, 'alphanumeric': 154, 'byte': 106, 'kanji': 65},
        'Q': {'bits': 608, 'numeric': 178, 'alphanumeric': 108, 'byte': 74, 'kanji': 45},
        'H': {'bits': 480, 'numeric': 139, 'alphanumeric': 84, 'byte': 58, 'kanji': 36},
    },
    7: {
        'L': {'bits': 1248, 'numeric': 370, 'alphanumeric': 224, 'byte': 154, 'kanji': 95},
        'M': {'bits': 992, 'numeric': 293, 'alphanumeric': 178, 'byte': 122, 'kanji': 75},
        'Q': {'bits': 704, 'numeric': 207, 'alphanumeric': 125, 'byte': 86, 'kanji': 53},
        'H': {'bits': 528, 'numeric': 154, 'alphanumeric': 93, 'byte': 64, 'kanji': 39},
    },
    8: {
        'L': {'bits': 1552, 'numeric': 461, 'alphanumeric': 279, 'byte': 192, 'kanji': 118},
        'M': {'bits': 1232, 'numeric': 365, 'alphanumeric': 221, 'byte': 152, 'kanji': 93},
        'Q': {'bits': 880, 'numeric': 259, 'alphanumeric': 157, 'byte': 108, 'kanji': 66},
        'H': {'bits': 688, 'numeric': 202, 'alphanumeric': 122, 'byte': 84, 'kanji': 52},
    },
    9: {
        'L': {'bits': 1856, 'numeric': 552, 'alphanumeric': 335, 'byte': 230, 'kanji': 141},
        'M': {'bits': 1456, 'numeric': 432, 'alphanumeric': 262, 'byte': 180, 'kanji': 111},
        'Q': {'bits': 1056, 'numeric': 312, 'alphanumeric': 189, 'byte': 130, 'kanji': 80},
        'H': {'bits': 800, 'numeric': 235, 'alphanumeric': 143, 'byte': 98, 'kanji': 60},
    },
    10: {
        'L': {'bits': 2192, 'numeric': 652, 'alphanumeric': 395, 'byte': 271, 'kanji': 167},
        'M': {'bits': 1728, 'numeric': 513, 'alphanumeric': 311, 'byte': 213, 'kanji': 131},
        'Q': {'bits': 1232, 'numeric': 364, 'alphanumeric': 221, 'byte': 151, 'kanji': 93},
        'H': {'bits': 976, 'numeric': 288, 'alphanumeric': 174, 'byte': 119, 'kanji': 74},
    },
    11: {
        'L': {'bits': 2592, 'numeric': 772, 'alphanumeric': 468, 'byte': 321, 'kanji': 198},
        'M': {'bits': 2032, 'numeric': 604, 'alphanumeric': 366, 'byte': 251, 'kanji': 155},
        'Q': {'bits': 1440, 'numeric': 427, 'alphanumeric': 259, 'byte': 177, 'kanji': 109},
        'H': {'bits': 1120, 'numeric': 331, 'alphanumeric': 200, 'byte': 137, 'kanji': 85},
    },
    12: {
        'L': {'bits': 2960, 'numeric': 883, 'alphanumeric': 535, 'byte': 367, 'kanji': 226},
        'M': {'bits': 2320, 'numeric': 691, 'alphanumeric': 419, 'byte': 287, 'kanji': 177},
        'Q': {'bits': 1648, 'numeric': 489, 'alphanumeric': 296, 'byte': 203, 'kanji': 125},
        'H': {'bits': 1264, 'numeric': 374, 'alphanumeric': 227, 'byte': 155, 'kanji': 96},
    },
    13: {
        'L': {'bits': 3424, 'numeric': 1022, 'alphanumeric': 619, 'byte': 425, 'kanji': 262},
        'M': {'bits': 2672, 'numeric': 796, 'alphanumeric': 483, 'byte': 331, 'kanji': 204},
        'Q': {'bits': 1952, 'numeric': 580, 'alphanumeric': 352, 'byte': 241, 'kanji': 149},
        'H': {'bits': 1440, 'numeric': 427, 'alphanumeric': 259, 'byte': 177, 'kanji': 109},
    },
    14: {
        'L': {'bits': 3688, 'numeric': 1101, 'alphanumeric': 667, 'byte': 458, 'kanji': 282},
        'M': {'bits': 2920, 'numeric': 871, 'alphanumeric': 528, 'byte': 362, 'kanji': 223},
        'Q': {'bits': 2088, 'numeric': 621, 'alphanumeric': 376, 'byte': 258, 'kanji': 159},
        'H': {'bits': 1576, 'numeric': 468, 'alphanumeric': 283, 'byte': 194, 'kanji': 120},
    },
    15: {
        'L': {'bits': 4184, 'numeric': 1250, 'alphanumeric': 758, 'byte': 520, 'kanji': 320},
        'M': {'bits': 3320, 'numeric': 991, 'alphanumeric': 600, 'byte': 412, 'kanji': 254},
        'Q': {'bits': 2360, 'numeric': 703, 'alphanumeric': 426, 'byte': 292, 'kanji': 180},
        'H': {'bits': 1784, 'numeric': 530, 'alphanumeric': 321, 'byte': 220, 'kanji': 136},
    },
    16: {
        'L': {'bits': 4712, 'numeric': 1408, 'alphanumeric': 854, 'byte': 586, 'kanji': 361},
        'M': {'bits': 3624, 'numeric': 1082, 'alphanumeric': 656, 'byte': 450, 'kanji': 277},
        'Q': {'bits': 2600, 'numeric': 775, 'alphanumeric': 470, 'byte': 322, 'kanji': 198},
        'H': {'bits': 2024, 'numeric': 602, 'alphanumeric': 365, 'byte': 250, 'kanji': 154},
    },
    17: {
        'L': {'bits': 5176, 'numeric': 1548, 'alphanumeric': 938, 'byte': 644, 'kanji': 397},
        'M': {'bits': 4056, 'numeric': 1212, 'alphanumeric': 734, 'byte': 504, 'kanji': 310},
        'Q': {'bits': 2936, 'numeric': 876, 'alphanumeric': 531, 'byte': 364, 'kanji': 224},
        'H': {'bits': 2264, 'numeric': 674, 'alphanumeric': 408, 'byte': 280, 'kanji': 173},
    },
    18: {
        'L': {'bits': 5768, 'numeric': 1725, 'alphanumeric': 1046, 'byte': 718, 'kanji': 442},
        'M': {'bits': 4504, 'numeric': 1346, 'alphanumeric': 816, 'byte': 560, 'kanji': 345},
        'Q': {'bits': 3176, 'numeric': 948, 'alphanumeric': 574, 'byte': 394, 'kanji': 243},
        'H': {'bits': 2504, 'numeric': 746, 'alphanumeric': 452, 'byte': 310, 'kanji': 191},
    },
    19: {
        'L': {'bits': 6360, 'numeric': 1903, 'alphanumeric': 1153, 'byte': 792, 'kanji': 488},
        'M': {'bits': 5016, 'numeric': 1500, 'alphanumeric': 909, 'byte': 624, 'kanji': 384},
        'Q': {'bits': 3560, 'numeric': 1063, 'alphanumeric': 644, 'byte': 442, 'kanji': 272},
        'H': {'bits': 2728, 'numeric': 813, 'alphanumeric': 493, 'byte': 338, 'kanji': 208},
    },
    20: {
        'L': {'bits': 6888, 'numeric': 2061, 'alphanumeric': 1249, 'byte': 858, 'kanji': 528},
        'M': {'bits': 5352, 'numeric': 1600, 'alphanumeric': 970, 'byte': 666, 'kanji': 410},
        'Q': {'bits': 3880, 'numeric': 1159, 'alphanumeric': 702, 'byte': 482, 'kanji': 297},
        'H': {'bits': 3080, 'numeric': 919, 'alphanumeric': 557, 'byte': 382, 'kanji': 235},
    },
    21: {
        'L': {'bits': 7456, 'numeric': 2232, 'alphanumeric': 1352, 'byte': 929, 'kanji': 572},
        'M': {'bits': 5712, 'numeric': 1708, 'alphanumeric': 1035, 'byte': 711, 'kanji': 438},
        'Q': {'bits': 4096, 'numeric': 1224, 'alphanumeric': 742, 'byte': 509, 'kanji': 314},
        'H': {'bits': 3248, 'numeric': 969, 'alphanumeric': 587, 'byte': 403, 'kanji': 248},
    },
    22: {
        'L': {'bits': 8048, 'numeric': 2409, 'alphanumeric': 1460, 'byte': 1003, 'kanji': 618},
        'M': {'bits': 6256, 'numeric': 1872, 'alphanumeric': 1134, 'byte': 779, 'kanji': 480},
        'Q': {'bits': 4544, 'numeric': 1358, 'alphanumeric': 823, 'byte': 565, 'kanji': 348},
        'H': {'bits': 3536, 'numeric': 1056, 'alphanumeric': 640, 'byte': 439, 'kanji': 270},
    },
    23: {
        'L': {'bits': 8752, 'numeric': 2620, 'alphanumeric': 1588, 'byte': 1091, 'kanji': 672},
        'M': {'bits': 6880, 'numeric': 2059, 'alphanumeric': 1248, 'byte': 857, 'kanji': 528},
        'Q': {'bits': 4912, 'numeric': 1468, 'alphanumeric': 890, 'byte': 611, 'kanji': 376},
        'H': {'bits': 3712, 'numeric': 1108, 'alphanumeric': 672, 'byte': 461, 'kanji': 284},
    },
    24: {
        'L': {'bits': 9392, 'numeric': 2812, 'alphanumeric': 1704, 'byte': 1171, 'kanji': 721},
        'M': {'bits': 7312, 'numeric': 2188, 'alphanumeric': 1326, 'byte': 911, 'kanji': 561},
        'Q': {'bits': 5312, 'numeric': 1588, 'alphanumeric': 963, 'byte': 661, 'kanji': 407},
        'H': {'bits': 4112, 'numeric': 1228, 'alphanumeric': 744, 'byte': 511, 'kanji': 315},
    },
    25: {
        'L': {'bits': 10208, 'numeric': 3057, 'alphanumeric': 1853, 'byte': 1273, 'kanji': 784},
        'M': {'bits': 8000, 'numeric': 2395, 'alphanumeric': 1451, 'byte': 997, 'kanji': 614},
        'Q': {'bits': 5744, 'numeric': 1718, 'alphanumeric': 1041, 'byte': 715, 'kanji': 440},
        'H': {'bits': 4304, 'numeric': 1286, 'alphanumeric': 779, 'byte': 535, 'kanji': 330},
    },
    26: {
        'L': {'bits': 10960, 'numeric': 3283, 'alphanumeric': 1990, 'byte': 1367, 'kanji': 842},
        'M': {'bits': 8496, 'numeric': 2544, 'alphanumeric': 1542, 'byte': 1059, 'kanji': 652},
        'Q': {'bits': 6032, 'numeric': 1804, 'alphanumeric': 1094, 'byte': 751, 'kanji': 462},
        'H': {'bits': 4768, 'numeric': 1425, 'alphanumeric': 864, 'byte': 593, 'kanji': 365},
    },
    27: {
        'L': {'bits': 11744, 'numeric': 3517, 'alphanumeric': 2132, 'byte': 1465, 'kanji': 902},
        'M': {'bits': 9024, 'numeric': 2701, 'alphanumeric': 1637, 'byte': 1125, 'kanji': 692},
        'Q': {'bits': 6464, 'numeric': 1933, 'alphanumeric': 1172, 'byte': 805, 'kanji': 496},
        'H': {'bits': 5024, 'numeric': 1501, 'alphanumeric': 910, 'byte': 625, 'kanji': 385},
    },
    28: {
        'L': {'bits': 12248, 'numeric': 3669, 'alphanumeric': 2223, 'byte': 1528, 'kanji': 940},
        'M': {'bits': 9544, 'numeric': 2857, 'alphanumeric': 1732, 'byte': 1190, 'kanji': 732},
        'Q': {'bits': 6968, 'numeric': 2085, 'alphanumeric': 1263, 'byte': 868, 'kanji': 534},
        'H': {'bits': 5288, 'numeric': 1581, 'alphanumeric': 958, 'byte': 658, 'kanji': 405},
    },
    29: {
        'L': {'bits': 13048, 'numeric': 3909, 'alphanumeric': 2369, 'byte': 1628, 'kanji': 1002},
        'M': {'bits': 10136, 'numeric': 3035, 'alphanumeric': 1839, 'byte': 1264, 'kanji': 778},
        'Q': {'bits': 7288, 'numeric': 2181, 'alphanumeric': 1322, 'byte': 908, 'kanji': 559},
        'H': {'bits': 5608, 'numeric': 1677, 'alphanumeric': 1016, 'byte': 698, 'kanji': 430},
    },
    30: {
        'L': {'bits': 13880, 'numeric': 4158, 'alphanumeric': 2520, 'byte': 1732, 'kanji': 1066},
        'M': {'bits': 10984, 'numeric': 3289, 'alphanumeric': 1994, 'byte': 1370, 'kanji': 843},
        'Q': {'bits': 7880, 'numeric': 2358, 'alphanumeric': 1429, 'byte': 982, 'kanji': 604},
        'H': {'bits': 5960, 'numeric': 1782, 'alphanumeric': 1080, 'byte': 742, 'kanji': 457},
    },
    31: {
        'L': {'bits': 14744, 'numeric': 4417, 'alphanumeric': 2677, 'byte': 1840, 'kanji': 1132},
        'M': {'bits': 11640, 'numeric': 3486, 'alphanumeric': 2113, 'byte': 1452, 'kanji': 894},
        'Q': {'bits': 8264, 'numeric': 2473, 'alphanumeric': 1499, 'byte': 1030, 'kanji': 634},
        'H': {'bits': 6344, 'numeric': 1897, 'alphanumeric': 1150, 'byte': 790, 'kanji': 486},
    },
    32: {
        'L': {'bits': 15640, 'numeric': 4686, 'alphanumeric': 2840, 'byte': 1952, 'kanji': 1201},
        'M': {'bits': 12328, 'numeric': 3693, 'alphanumeric': 2238, 'byte': 1538, 'kanji': 947},
        'Q': {'bits': 8920, 'numeric': 2670, 'alphanumeric': 1618, 'byte': 1112, 'kanji': 684},
        'H': {'bits': 6760, 'numeric': 2022, 'alphanumeric': 1226, 'byte': 842, 'kanji': 518},
    },
    33: {
        'L': {'bits': 16568, 'numeric': 4965, 'alphanumeric': 3009, 'byte': 2068, 'kanji': 1273},
        'M': {'bits': 13048, 'numeric': 3909, 'alphanumeric': 2369, 'byte': 1628, 'kanji': 1002},
        'Q': {'bits': 9368, 'numeric': 2805, 'alphanumeric': 1700, 'byte': 1168, 'kanji': 719},
        'H': {'bits': 7208, 'numeric': 2157, 'alphanumeric': 1307, 'byte': 898, 'kanji': 553},
    },
    34: {
        'L': {'bits': 17528, 'numeric': 5253, 'alphanumeric': 3183, 'byte': 2188, 'kanji': 1347},
        'M': {'bits': 13800, 'numeric': 4134, 'alphanumeric': 2506, 'byte': 1722, 'kanji': 1060},
        'Q': {'bits': 9848, 'numeric': 2949, 'alphanumeric': 1787, 'byte': 1228, 'kanji': 756},
        'H': {'bits': 7688, 'numeric': 2301, 'alphanumeric': 1394, 'byte': 958, 'kanji': 590},
    },
    35: {
        'L': {'bits': 18448, 'numeric': 5529, 'alphanumeric': 3351, 'byte': 2303, 'kanji': 1417},
        'M': {'bits': 14496, 'numeric': 4343, 'alphanumeric': 2632, 'byte': 1809, 'kanji': 1113},
        'Q': {'bits': 10288, 'numeric': 3081, 'alphanumeric': 1867, 'byte': 1283, 'kanji': 790},
        'H': {'bits': 7888, 'numeric': 2361, 'alphanumeric': 1431, 'byte': 983, 'kanji': 605},
    },
    36: {
        'L': {'bits': 19472, 'numeric': 5836, 'alphanumeric': 3537, 'byte': 2431, 'kanji': 1496},
        'M': {'bits': 15312, 'numeric': 4588, 'alphanumeric': 2780, 'byte': 1911, 'kanji': 1176},
        'Q': {'bits': 10832, 'numeric': 3244, 'alphanumeric': 1966, 'byte': 1351, 'kanji': 832},
        'H': {'bits': 8432, 'numeric': 2524, 'alphanumeric': 1530, 'byte': 1051, 'kanji': 647},
    },
    37: {
        'L': {'bits': 20528, 'numeric': 6153, 'alphanumeric': 3729, 'byte': 2563, 'kanji': 1577},
        'M': {'bits': 15936, 'numeric': 4775, 'alphanumeric': 2894, 'byte': 1989, 'kanji': 1224},
        'Q': {'bits': 11408, 'numeric': 3417, 'alphanumeric': 2071, 'byte': 1423, 'kanji': 876},
        'H': {'bits': 8768, 'numeric': 2625, 'alphanumeric': 1591, 'byte': 1093, 'kanji': 673},
    },
    38: {
        'L': {'bits': 21616, 'numeric': 6479, 'alphanumeric': 3927, 'byte': 2699, 'kanji': 1661},
        'M': {'bits': 16816, 'numeric': 5039, 'alphanumeric': 3054, 'byte': 2099, 'kanji': 1292},
        'Q': {'bits': 12016, 'numeric': 3599, 'alphanumeric': 2181, 'byte': 1499, 'kanji': 923},
        'H': {'bits': 9136, 'numeric': 2735, 'alphanumeric': 1658, 'byte': 1139, 'kanji': 701},
    },
    39: {
        'L': {'bits': 22496, 'numeric': 6743, 'alphanumeric': 4087, 'byte': 2809, 'kanji': 1729},
        'M': {'bits': 17728, 'numeric': 5313, 'alphanumeric': 3220, 'byte': 2213, 'kanji': 1362},
        'Q': {'bits': 12656, 'numeric': 3791, 'alphanumeric': 2298, 'byte': 1579, 'kanji': 972},
        'H': {'bits': 9776, 'numeric': 2927, 'alphanumeric': 1774, 'byte': 1219, 'kanji': 750},
    },
    40: {
        'L': {'bits': 23648, 'numeric': 7089, 'alphanumeric': 4296, 'byte': 2953, 'kanji': 1817},
        'M': {'bits': 18672, 'numeric': 5596, 'alphanumeric': 3391, 'byte': 2331, 'kanji': 1435},
        'Q': {'bits': 13328, 'numeric': 3993, 'alphanumeric': 2420, 'byte': 1663, 'kanji': 1024},
        'H': {'bits': 10208, 'numeric': 3057, 'alphanumeric': 1852, 'byte': 1273, 'kanji': 784},
    },
}

# QR error correction codewords and block information by version and error correction level
error_correction = {
    1: {
        'L': {'codewords': 19, 'ec_codewords_per_block': 7, 'blocks_in_group_1': 1, 'codewords_in_group_1': 19, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 16, 'ec_codewords_per_block': 10, 'blocks_in_group_1': 1, 'codewords_in_group_1': 16, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 13, 'ec_codewords_per_block': 13, 'blocks_in_group_1': 1, 'codewords_in_group_1': 13, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'H': {'codewords': 9, 'ec_codewords_per_block': 17, 'blocks_in_group_1': 1, 'codewords_in_group_1': 9, 'blocks_in_group_2':  0, 'codewords_in_group_2': 0},
    },
    2: {
        'L': {'codewords': 34, 'ec_codewords_per_block': 10, 'blocks_in_group_1': 1, 'codewords_in_group_1': 34, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 28, 'ec_codewords_per_block': 16, 'blocks_in_group_1': 1, 'codewords_in_group_1': 28, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 22, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 1, 'codewords_in_group_1': 22, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'H': {'codewords': 16, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 1, 'codewords_in_group_1': 16, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
    },
    3: {
        'L': {'codewords': 55, 'ec_codewords_per_block': 15, 'blocks_in_group_1': 1, 'codewords_in_group_1': 55, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 44, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 1, 'codewords_in_group_1': 44, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 34, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 2, 'codewords_in_group_1': 17, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'H': {'codewords': 26, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 2, 'codewords_in_group_1': 13, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
    },
    4: {
        'L': {'codewords': 80, 'ec_codewords_per_block': 20, 'blocks_in_group_1': 1, 'codewords_in_group_1': 80, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 64, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 2, 'codewords_in_group_1': 32, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 48, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 2, 'codewords_in_group_1': 24, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'H': {'codewords': 36, 'ec_codewords_per_block': 16, 'blocks_in_group_1': 4, 'codewords_in_group_1': 9, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
    },
    5: {
        'L': {'codewords': 108, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 1, 'codewords_in_group_1': 108, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 86, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 2, 'codewords_in_group_1': 43, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 62, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 2, 'codewords_in_group_1': 15, 'blocks_in_group_2': 2, 'codewords_in_group_2': 16},
        'H': {'codewords': 46, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 2, 'codewords_in_group_1': 11, 'blocks_in_group_2': 2, 'codewords_in_group_2': 12},
    },
    6: {
        'L': {'codewords': 136, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 2, 'codewords_in_group_1': 68, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 108, 'ec_codewords_per_block': 16, 'blocks_in_group_1': 4, 'codewords_in_group_1': 27, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 76, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 4, 'codewords_in_group_1': 19, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'H': {'codewords': 60, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 4, 'codewords_in_group_1': 15, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
    },
    7: {
        'L': {'codewords': 156, 'ec_codewords_per_block': 20, 'blocks_in_group_1': 2, 'codewords_in_group_1': 78, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 124, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 4, 'codewords_in_group_1': 31, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 88, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 2, 'codewords_in_group_1': 14, 'blocks_in_group_2': 4, 'codewords_in_group_2': 15},
        'H': {'codewords': 66, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 4, 'codewords_in_group_1': 13, 'blocks_in_group_2': 1, 'codewords_in_group_2': 14},
    },
    8: {
        'L': {'codewords': 194, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 2, 'codewords_in_group_1': 97, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 154, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 2, 'codewords_in_group_1': 38, 'blocks_in_group_2': 2, 'codewords_in_group_2': 39},
        'Q': {'codewords': 110, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 4, 'codewords_in_group_1': 18, 'blocks_in_group_2': 2, 'codewords_in_group_2': 19},
        'H': {'codewords': 86, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 4, 'codewords_in_group_1': 14, 'blocks_in_group_2': 2, 'codewords_in_group_2': 15},
    },
    9: {
        'L': {'codewords': 232, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 2, 'codewords_in_group_1': 116, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 182, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 3, 'codewords_in_group_1': 36, 'blocks_in_group_2': 2, 'codewords_in_group_2': 37},
        'Q': {'codewords': 132, 'ec_codewords_per_block': 20, 'blocks_in_group_1': 4, 'codewords_in_group_1': 16, 'blocks_in_group_2': 4, 'codewords_in_group_2': 17},
        'H': {'codewords': 100, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 4, 'codewords_in_group_1': 12, 'blocks_in_group_2': 4, 'codewords_in_group_2': 13},
    },
    10: {
        'L': {'codewords': 274, 'ec_codewords_per_block': 18, 'blocks_in_group_1': 2, 'codewords_in_group_1': 68, 'blocks_in_group_2': 2, 'codewords_in_group_2': 69},
        'M': {'codewords': 216, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 4, 'codewords_in_group_1': 43, 'blocks_in_group_2': 1, 'codewords_in_group_2': 44},
        'Q': {'codewords': 154, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 6, 'codewords_in_group_1': 19, 'blocks_in_group_2': 2, 'codewords_in_group_2': 20},
        'H': {'codewords': 122, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 6, 'codewords_in_group_1': 15, 'blocks_in_group_2': 2, 'codewords_in_group_2': 16},
    },
    11: {
        'L': {'codewords': 324, 'ec_codewords_per_block': 20, 'blocks_in_group_1': 4, 'codewords_in_group_1': 81, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 254, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 1, 'codewords_in_group_1': 50, 'blocks_in_group_2': 4, 'codewords_in_group_2': 51},
        'Q': {'codewords': 180, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 4, 'codewords_in_group_1': 22, 'blocks_in_group_2': 4, 'codewords_in_group_2': 23},
        'H': {'codewords': 140, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 3, 'codewords_in_group_1': 12, 'blocks_in_group_2': 8, 'codewords_in_group_2': 13},
    },
    12: {
        'L': {'codewords': 370, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 2, 'codewords_in_group_1': 92, 'blocks_in_group_2': 2, 'codewords_in_group_2': 93},
        'M': {'codewords': 290, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 6, 'codewords_in_group_1': 36, 'blocks_in_group_2': 2, 'codewords_in_group_2': 37},
        'Q': {'codewords': 206, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 4, 'codewords_in_group_1': 20, 'blocks_in_group_2': 6, 'codewords_in_group_2': 21},
        'H': {'codewords': 158, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 7, 'codewords_in_group_1': 14, 'blocks_in_group_2': 4, 'codewords_in_group_2': 15},
    },
    13: {
        'L': {'codewords': 428, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 4, 'codewords_in_group_1': 107, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 334, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 8, 'codewords_in_group_1': 37, 'blocks_in_group_2': 1, 'codewords_in_group_2': 38},
        'Q': {'codewords': 244, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 8, 'codewords_in_group_1': 20, 'blocks_in_group_2': 4, 'codewords_in_group_2': 21},
        'H': {'codewords': 180, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 12, 'codewords_in_group_1': 11, 'blocks_in_group_2': 4, 'codewords_in_group_2': 12},
    },
    14: {
        'L': {'codewords': 461, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 3, 'codewords_in_group_1': 115, 'blocks_in_group_2': 1, 'codewords_in_group_2': 116},
        'M': {'codewords': 365, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 4, 'codewords_in_group_1': 40, 'blocks_in_group_2': 5, 'codewords_in_group_2': 41},
        'Q': {'codewords': 261, 'ec_codewords_per_block': 20, 'blocks_in_group_1': 11, 'codewords_in_group_1': 16, 'blocks_in_group_2': 5, 'codewords_in_group_2': 17},
        'H': {'codewords': 197, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 11, 'codewords_in_group_1': 12, 'blocks_in_group_2': 5, 'codewords_in_group_2': 13},
    },
    15: {
        'L': {'codewords': 523, 'ec_codewords_per_block': 22, 'blocks_in_group_1': 5, 'codewords_in_group_1': 87, 'blocks_in_group_2': 1, 'codewords_in_group_2': 88},
        'M': {'codewords': 415, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 5, 'codewords_in_group_1': 41, 'blocks_in_group_2': 5, 'codewords_in_group_2': 42},
        'Q': {'codewords': 295, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 5, 'codewords_in_group_1': 24, 'blocks_in_group_2': 7, 'codewords_in_group_2': 25},
        'H': {'codewords': 223, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 11, 'codewords_in_group_1': 12, 'blocks_in_group_2': 7, 'codewords_in_group_2': 13},
    },
    16: {
        'L': {'codewords': 589, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 5, 'codewords_in_group_1': 98, 'blocks_in_group_2': 1, 'codewords_in_group_2': 99},
        'M': {'codewords': 453, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 7, 'codewords_in_group_1': 45, 'blocks_in_group_2': 3, 'codewords_in_group_2': 46},
        'Q': {'codewords': 325, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 15, 'codewords_in_group_1': 19, 'blocks_in_group_2': 2, 'codewords_in_group_2': 20},
        'H': {'codewords': 253, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 3, 'codewords_in_group_1': 15, 'blocks_in_group_2': 13, 'codewords_in_group_2': 16},
    },
    17: {
        'L': {'codewords': 647, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 1, 'codewords_in_group_1': 107, 'blocks_in_group_2': 5, 'codewords_in_group_2': 108},
        'M': {'codewords': 507, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 10, 'codewords_in_group_1': 46, 'blocks_in_group_2': 1, 'codewords_in_group_2': 47},
        'Q': {'codewords': 367, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 1, 'codewords_in_group_1': 22, 'blocks_in_group_2': 15, 'codewords_in_group_2': 23},
        'H': {'codewords': 283, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 2, 'codewords_in_group_1': 14, 'blocks_in_group_2': 17, 'codewords_in_group_2': 15},
    },
    18: {
        'L': {'codewords': 721, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 5, 'codewords_in_group_1': 120, 'blocks_in_group_2': 1, 'codewords_in_group_2': 121},
        'M': {'codewords': 563, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 9, 'codewords_in_group_1': 43, 'blocks_in_group_2': 4, 'codewords_in_group_2': 44},
        'Q': {'codewords': 397, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 17, 'codewords_in_group_1': 22, 'blocks_in_group_2': 1, 'codewords_in_group_2': 23},
        'H': {'codewords': 313, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 2, 'codewords_in_group_1': 14, 'blocks_in_group_2': 19, 'codewords_in_group_2': 15},
    },
    19: {
        'L': {'codewords': 795, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 3, 'codewords_in_group_1': 113, 'blocks_in_group_2': 4, 'codewords_in_group_2': 114},
        'M': {'codewords': 627, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 3, 'codewords_in_group_1': 44, 'blocks_in_group_2': 11, 'codewords_in_group_2': 45},
        'Q': {'codewords': 445, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 17, 'codewords_in_group_1': 21, 'blocks_in_group_2': 4, 'codewords_in_group_2': 22},
        'H': {'codewords': 341, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 9, 'codewords_in_group_1': 13, 'blocks_in_group_2': 16, 'codewords_in_group_2': 14},
    },
    20: {
        'L': {'codewords': 861, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 3, 'codewords_in_group_1': 107, 'blocks_in_group_2': 5, 'codewords_in_group_2': 108},
        'M': {'codewords': 669, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 3, 'codewords_in_group_1': 41, 'blocks_in_group_2': 13, 'codewords_in_group_2': 42},
        'Q': {'codewords': 485, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 15, 'codewords_in_group_1': 24, 'blocks_in_group_2': 5, 'codewords_in_group_2': 25},
        'H': {'codewords': 385, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 15, 'codewords_in_group_1': 15, 'blocks_in_group_2': 10, 'codewords_in_group_2': 16},
    },
    21: {
        'L': {'codewords': 932, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 4, 'codewords_in_group_1': 116, 'blocks_in_group_2': 4, 'codewords_in_group_2': 117},
        'M': {'codewords': 714, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 17, 'codewords_in_group_1': 42, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 512, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 17, 'codewords_in_group_1': 22, 'blocks_in_group_2': 6, 'codewords_in_group_2': 23},
        'H': {'codewords': 406, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 19, 'codewords_in_group_1': 16, 'blocks_in_group_2': 6, 'codewords_in_group_2': 17},
    },
    22: {
        'L': {'codewords': 1006, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 2, 'codewords_in_group_1': 111, 'blocks_in_group_2': 7, 'codewords_in_group_2': 112},
        'M': {'codewords': 782, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 17, 'codewords_in_group_1': 46, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'Q': {'codewords': 568, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 7, 'codewords_in_group_1': 24, 'blocks_in_group_2': 16, 'codewords_in_group_2': 25},
        'H': {'codewords': 442, 'ec_codewords_per_block': 24, 'blocks_in_group_1': 34, 'codewords_in_group_1': 13, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
    },
    23: {
        'L': {'codewords': 1094, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 4, 'codewords_in_group_1': 121, 'blocks_in_group_2': 5, 'codewords_in_group_2': 122},
        'M': {'codewords': 860, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 4, 'codewords_in_group_1': 47, 'blocks_in_group_2': 14, 'codewords_in_group_2': 48},
        'Q': {'codewords': 614, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 11, 'codewords_in_group_1': 24, 'blocks_in_group_2': 14, 'codewords_in_group_2': 25},
        'H': {'codewords': 464, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 16, 'codewords_in_group_1': 15, 'blocks_in_group_2': 14, 'codewords_in_group_2': 16},
    },
    24: {
        'L': {'codewords': 1174, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 6, 'codewords_in_group_1': 117, 'blocks_in_group_2': 4, 'codewords_in_group_2': 118},
        'M': {'codewords': 914, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 6, 'codewords_in_group_1': 45, 'blocks_in_group_2': 14, 'codewords_in_group_2': 46},
        'Q': {'codewords': 664, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 11, 'codewords_in_group_1': 24, 'blocks_in_group_2': 16, 'codewords_in_group_2': 25},
        'H': {'codewords': 514, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 30, 'codewords_in_group_1': 16, 'blocks_in_group_2': 2, 'codewords_in_group_2': 17},
    },
    25: {
        'L': {'codewords': 1276, 'ec_codewords_per_block': 26, 'blocks_in_group_1': 8, 'codewords_in_group_1': 106, 'blocks_in_group_2': 4, 'codewords_in_group_2': 107},
        'M': {'codewords': 1000, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 8, 'codewords_in_group_1': 47, 'blocks_in_group_2': 13, 'codewords_in_group_2': 48},
        'Q': {'codewords': 718, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 7, 'codewords_in_group_1': 24, 'blocks_in_group_2': 22, 'codewords_in_group_2': 25},
        'H': {'codewords': 538, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 22, 'codewords_in_group_1': 15, 'blocks_in_group_2': 13, 'codewords_in_group_2': 16},
    },
    26: {
        'L': {'codewords': 1370, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 10, 'codewords_in_group_1': 114, 'blocks_in_group_2': 2, 'codewords_in_group_2': 115},
        'M': {'codewords': 1062, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 19, 'codewords_in_group_1': 46, 'blocks_in_group_2': 4, 'codewords_in_group_2': 47},
        'Q': {'codewords': 754, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 28, 'codewords_in_group_1': 22, 'blocks_in_group_2': 6, 'codewords_in_group_2': 23},
        'H': {'codewords': 596, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 33, 'codewords_in_group_1': 16, 'blocks_in_group_2': 4, 'codewords_in_group_2': 17},
    },
    27: {
        'L': {'codewords': 1468, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 8, 'codewords_in_group_1': 122, 'blocks_in_group_2': 4, 'codewords_in_group_2': 123},
        'M': {'codewords': 1128, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 22, 'codewords_in_group_1': 45, 'blocks_in_group_2': 3, 'codewords_in_group_2': 46},
        'Q': {'codewords': 808, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 8, 'codewords_in_group_1': 23, 'blocks_in_group_2': 26, 'codewords_in_group_2': 24},
        'H': {'codewords': 628, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 12, 'codewords_in_group_1': 15, 'blocks_in_group_2': 28, 'codewords_in_group_2': 16},
    },
    28: {
        'L': {'codewords': 1531, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 3, 'codewords_in_group_1': 117, 'blocks_in_group_2': 10, 'codewords_in_group_2': 118},
        'M': {'codewords': 1193, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 3, 'codewords_in_group_1': 45, 'blocks_in_group_2': 23, 'codewords_in_group_2': 46},
        'Q': {'codewords': 871, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 4, 'codewords_in_group_1': 24, 'blocks_in_group_2': 31, 'codewords_in_group_2': 25},
        'H': {'codewords': 661, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 11, 'codewords_in_group_1': 15, 'blocks_in_group_2': 31, 'codewords_in_group_2': 16},
    },
    29: {
        'L': {'codewords': 1631, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 7, 'codewords_in_group_1': 116, 'blocks_in_group_2': 7, 'codewords_in_group_2': 117},
        'M': {'codewords': 1267, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 21, 'codewords_in_group_1': 45, 'blocks_in_group_2': 7, 'codewords_in_group_2': 46},
        'Q': {'codewords': 911, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 1, 'codewords_in_group_1': 23, 'blocks_in_group_2': 37, 'codewords_in_group_2': 24},
        'H': {'codewords': 701, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 19, 'codewords_in_group_1': 15, 'blocks_in_group_2': 26, 'codewords_in_group_2': 16},
    },
    30: {
        'L': {'codewords': 1735, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 5, 'codewords_in_group_1': 115, 'blocks_in_group_2': 10, 'codewords_in_group_2': 116},
        'M': {'codewords': 1373, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 19, 'codewords_in_group_1': 47, 'blocks_in_group_2': 10, 'codewords_in_group_2': 48},
        'Q': {'codewords': 985, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 15, 'codewords_in_group_1': 24, 'blocks_in_group_2': 25, 'codewords_in_group_2': 25},
        'H': {'codewords': 745, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 23, 'codewords_in_group_1': 15, 'blocks_in_group_2': 25, 'codewords_in_group_2': 16},
    },
    31: {
        'L': {'codewords': 1843, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 13, 'codewords_in_group_1': 115, 'blocks_in_group_2': 3, 'codewords_in_group_2': 116},
        'M': {'codewords': 1455, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 2, 'codewords_in_group_1': 46, 'blocks_in_group_2': 29, 'codewords_in_group_2': 47},
        'Q': {'codewords': 1033, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 42, 'codewords_in_group_1': 24, 'blocks_in_group_2': 1, 'codewords_in_group_2': 25},
        'H': {'codewords': 793, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 23, 'codewords_in_group_1': 15, 'blocks_in_group_2': 28, 'codewords_in_group_2': 16},
    },
    32: {
        'L': {'codewords': 1955, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 17, 'codewords_in_group_1': 115, 'blocks_in_group_2': 0, 'codewords_in_group_2': 0},
        'M': {'codewords': 1541, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 10, 'codewords_in_group_1': 46, 'blocks_in_group_2': 23, 'codewords_in_group_2': 47},
        'Q': {'codewords': 1115, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 10, 'codewords_in_group_1': 24, 'blocks_in_group_2': 35, 'codewords_in_group_2': 25},
        'H': {'codewords': 845, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 19, 'codewords_in_group_1': 15, 'blocks_in_group_2': 35, 'codewords_in_group_2': 16},
    },
    33: {
        'L': {'codewords': 2071, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 17, 'codewords_in_group_1': 115, 'blocks_in_group_2': 1, 'codewords_in_group_2': 116},
        'M': {'codewords': 1631, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 14, 'codewords_in_group_1': 46, 'blocks_in_group_2': 21, 'codewords_in_group_2': 47},
        'Q': {'codewords': 1171, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 29, 'codewords_in_group_1': 24, 'blocks_in_group_2': 19, 'codewords_in_group_2': 25},
        'H': {'codewords': 901, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 11, 'codewords_in_group_1': 15, 'blocks_in_group_2': 46, 'codewords_in_group_2': 16},
    },
    34: {
        'L': {'codewords': 2191, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 13, 'codewords_in_group_1': 115, 'blocks_in_group_2': 6, 'codewords_in_group_2': 116},
        'M': {'codewords': 1725, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 14, 'codewords_in_group_1': 46, 'blocks_in_group_2': 23, 'codewords_in_group_2': 47},
        'Q': {'codewords': 1231, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 44, 'codewords_in_group_1': 24, 'blocks_in_group_2': 7, 'codewords_in_group_2': 25},
        'H': {'codewords': 961, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 59, 'codewords_in_group_1': 16, 'blocks_in_group_2': 1, 'codewords_in_group_2': 17},
    },
    35: {
        'L': {'codewords': 2306, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 12, 'codewords_in_group_1': 121, 'blocks_in_group_2': 7, 'codewords_in_group_2': 122},
        'M': {'codewords': 1812, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 12, 'codewords_in_group_1': 47, 'blocks_in_group_2': 26, 'codewords_in_group_2': 48},
        'Q': {'codewords': 1286, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 39, 'codewords_in_group_1': 24, 'blocks_in_group_2': 14, 'codewords_in_group_2': 25},
        'H': {'codewords': 986, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 22, 'codewords_in_group_1': 15, 'blocks_in_group_2': 41, 'codewords_in_group_2': 16},
    },
    36: {
        'L': {'codewords': 2434, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 6, 'codewords_in_group_1': 121, 'blocks_in_group_2': 14, 'codewords_in_group_2': 122},
        'M': {'codewords': 1914, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 6, 'codewords_in_group_1': 47, 'blocks_in_group_2': 34, 'codewords_in_group_2': 48},
        'Q': {'codewords': 1354, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 46, 'codewords_in_group_1': 24, 'blocks_in_group_2': 10, 'codewords_in_group_2': 25},
        'H': {'codewords': 1054, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 2, 'codewords_in_group_1': 15, 'blocks_in_group_2': 64, 'codewords_in_group_2': 16},
    },
    37: {
        'L': {'codewords': 2566, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 17, 'codewords_in_group_1': 122, 'blocks_in_group_2': 4, 'codewords_in_group_2': 123},
        'M': {'codewords': 1992, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 29, 'codewords_in_group_1': 46, 'blocks_in_group_2': 14, 'codewords_in_group_2': 47},
        'Q': {'codewords': 1426, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 49, 'codewords_in_group_1': 24, 'blocks_in_group_2': 10, 'codewords_in_group_2': 25},
        'H': {'codewords': 1096, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 24, 'codewords_in_group_1': 15, 'blocks_in_group_2': 46, 'codewords_in_group_2': 16},
    },
    38: {
        'L': {'codewords': 2702, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 4, 'codewords_in_group_1': 122, 'blocks_in_group_2': 18, 'codewords_in_group_2': 123},
        'M': {'codewords': 2102, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 13, 'codewords_in_group_1': 46, 'blocks_in_group_2': 32, 'codewords_in_group_2': 47},
        'Q': {'codewords': 1502, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 48, 'codewords_in_group_1': 24, 'blocks_in_group_2': 14, 'codewords_in_group_2': 25},
        'H': {'codewords': 1142, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 42, 'codewords_in_group_1': 15, 'blocks_in_group_2': 32, 'codewords_in_group_2': 16},
    },
    39: {
        'L': {'codewords': 2812, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 20, 'codewords_in_group_1': 117, 'blocks_in_group_2': 4, 'codewords_in_group_2': 118},
        'M': {'codewords': 2216, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 40, 'codewords_in_group_1': 47, 'blocks_in_group_2': 7, 'codewords_in_group_2': 48},
        'Q': {'codewords': 1582, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 43, 'codewords_in_group_1': 24, 'blocks_in_group_2': 22, 'codewords_in_group_2': 25},
        'H': {'codewords': 1222, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 10, 'codewords_in_group_1': 15, 'blocks_in_group_2': 67, 'codewords_in_group_2': 16},
    },
    40: {
        'L': {'codewords': 2956, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 19, 'codewords_in_group_1': 118, 'blocks_in_group_2': 6, 'codewords_in_group_2': 119},
        'M': {'codewords': 2334, 'ec_codewords_per_block': 28, 'blocks_in_group_1': 18, 'codewords_in_group_1': 47, 'blocks_in_group_2': 31, 'codewords_in_group_2': 48},
        'Q': {'codewords': 1666, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 34, 'codewords_in_group_1': 24, 'blocks_in_group_2': 34, 'codewords_in_group_2': 25},
        'H': {'codewords': 1276, 'ec_codewords_per_block': 30, 'blocks_in_group_1': 20, 'codewords_in_group_1': 15, 'blocks_in_group_2': 61, 'codewords_in_group_2': 16},
    }
}

# number of error correction codewords and generator polynomials
generator_polynomials = {
    2: [0, 25, 1],
    5: [0, 113, 164, 166, 119, 10],
    6: [0, 116, 0, 134, 5, 176, 15],
    7: [0, 87, 229, 146, 149, 238, 102, 21],
    8: [0, 175, 238, 208, 249, 215, 252, 196, 28],
    10: [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45],
    13: [0, 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78],
    14: [0, 199, 249, 155, 48, 190, 124, 218, 137, 216, 87, 207, 59, 22, 91],
    15: [0, 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105],
    16: [0, 120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 225, 120],
    17: [0, 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136],
    18: [0, 215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153],
    20: [0, 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190],
    22: [0, 210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105, 165, 231],
    24: [0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232, 87, 96, 227, 21],
    26: [0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70],
    28: [0, 168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87, 42, 195, 212, 119, 242, 37, 9, 123],
    30: [0, 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193, 224, 130, 156, 37, 251, 216, 238, 40, 192, 180],
    32: [0, 10, 6, 106, 190, 249, 167, 4, 67, 209, 138, 138, 32, 242, 123, 89, 27, 120, 185, 80, 156, 38, 69, 171, 60, 28, 222, 80, 52, 254, 185, 220, 241],
    34: [0, 111, 77, 146, 94, 26, 21, 108, 19, 105, 94, 113, 193, 86, 140, 163, 125, 58, 158, 229, 239, 218, 103, 56, 70, 114, 61, 183, 129, 167, 13, 98, 62, 129, 51],
    36: [0, 200, 183, 98, 16, 172, 31, 246, 234, 60, 152, 115, 0, 167, 152, 113, 248, 238, 107, 18, 63, 218, 37, 87, 210, 105, 177, 120, 74, 121, 196, 117, 251, 113, 233, 30, 120],
    40: [0, 59, 116, 79, 161, 252, 98, 128, 205, 128, 161, 247, 57, 163, 56, 235, 106, 53, 26, 187, 174, 226, 104, 170, 7, 175, 35, 181, 114, 88, 41, 47, 163, 125, 134, 72, 20, 232, 53, 35, 15],
    42: [0, 250, 103, 221, 230, 25, 18, 137, 231, 0, 3, 58, 242, 221, 191, 110, 84, 230, 8, 188, 106, 96, 147, 15, 131, 139, 34, 101, 223, 39, 101, 213, 199, 237, 254, 201, 123, 171, 162, 194, 117, 50, 96],
    44: [0, 190, 7, 61, 121, 71, 246, 69, 55, 168, 188, 89, 243, 191, 25, 72, 123, 9, 145, 14, 247, 1, 238, 44, 78, 143, 62, 224, 126, 118, 114, 68, 163, 52, 194, 217, 147, 204, 169, 37, 130, 113, 102, 73, 181],
    46: [0, 112, 94, 88, 112, 253, 224, 202, 115, 187, 99, 89, 5, 54, 113, 129, 44, 58, 16, 135, 216, 169, 211, 36, 1, 4, 96, 60, 241, 73, 104, 234, 8, 249, 245, 119, 174, 52, 25, 157, 224, 43, 202, 223, 19, 82, 15],
    48: [0, 228, 25, 196, 130, 211, 146, 60, 24, 251, 90, 39, 102, 240, 61, 178, 63, 46, 123, 115, 18, 221, 111, 135, 160, 182, 205, 107, 206, 95, 150, 120, 184, 91, 21, 247, 156, 140, 238, 191, 11, 94, 227, 84, 50, 163, 39, 34, 108],
    50: [0, 232, 125, 157, 161, 164, 9, 118, 46, 209, 99, 203, 193, 35, 3, 209, 111, 195, 242, 203, 225, 46, 13, 32, 160, 126, 209, 130, 160, 242, 215, 242, 75, 77, 42, 189, 32, 113, 65, 124, 69, 228, 114, 235, 175, 124, 170, 215, 232, 133, 205],
    52: [0, 116, 50, 86, 186, 50, 220, 251, 89, 192, 46, 86, 127, 124, 19, 184, 233, 151, 215, 22, 14, 59, 145, 37, 242, 203, 134, 254, 89, 190, 94, 59, 65, 124, 113, 100, 233, 235, 121, 22, 76, 86, 97, 39, 242, 200, 220, 101, 33, 239, 254, 116, 51],
    54: [0, 183, 26, 201, 87, 210, 221, 113, 21, 46, 65, 45, 50, 238, 184, 249, 225, 102, 58, 209, 218, 109, 165, 26, 95, 184, 192, 52, 245, 35, 254, 238, 175, 172, 79, 123, 25, 122, 43, 120, 108, 215, 80, 128, 201, 235, 8, 153, 59, 101, 31, 198, 76, 31, 156],
    56: [0, 106, 120, 107, 157, 164, 216, 112, 116, 2, 91, 248, 163, 36, 201, 202, 229, 6, 144, 254, 155, 135, 208, 170, 209, 12, 139, 127, 142, 182, 249, 177, 174, 190, 28, 10, 85, 239, 184, 101, 124, 152, 206, 96, 23, 163, 61, 27, 196, 247, 151, 154, 202, 207, 20, 61, 10],
    58: [0, 82, 116, 26, 247, 66, 27, 62, 107, 252, 182, 200, 185, 235, 55, 251, 242, 210, 144, 154, 237, 176, 141, 192, 248, 152, 249, 206, 85, 253, 142, 65, 165, 125, 23, 24, 30, 122, 240, 214, 6, 129, 218, 29, 145, 127, 134, 206, 245, 117, 29, 41, 63, 159, 142, 233, 125, 148, 123],
    60: [0, 107, 140, 26, 12, 9, 141, 243, 197, 226, 197, 219, 45, 211, 101, 219, 120, 28, 181, 127, 6, 100, 247, 2, 205, 198, 57, 115, 219, 101, 109, 160, 82, 37, 38, 238, 49, 160, 209, 121, 86, 11, 124, 30, 181, 84, 25, 194, 87, 65, 102, 190, 220, 70, 27, 209, 16, 89, 7, 33, 240],
    62: [0, 65, 202, 113, 98, 71, 223, 248, 118, 214, 94, 0, 122, 37, 23, 2, 228, 58, 121, 7, 105, 135, 78, 243, 118, 70, 76, 223, 89, 72, 50, 70, 111, 194, 17, 212, 126, 181, 35, 221, 117, 235, 11, 229, 149, 147, 123, 213, 40, 115, 6, 200, 100, 26, 246, 182, 218, 127, 215, 36, 186, 110, 106],
    64: [0, 45, 51, 175, 9, 7, 158, 159, 49, 68, 119, 92, 123, 177, 204, 187, 254, 200, 78, 141, 149, 119, 26, 127, 53, 160, 93, 199, 212, 29, 24, 145, 156, 208, 150, 218, 209, 4, 216, 91, 47, 184, 146, 47, 140, 195, 195, 125, 242, 238, 63, 99, 108, 140, 230, 242, 31, 204, 11, 178, 243, 217, 156, 213, 231],
    66: [0, 5, 118, 222, 180, 136, 136, 162, 51, 46, 117, 13, 215, 81, 17, 139, 247, 197, 171, 95, 173, 65, 137, 178, 68, 111, 95, 101, 41, 72, 214, 169, 197, 95, 7, 44, 154, 77, 111, 236, 40, 121, 143, 63, 87, 80, 253, 240, 126, 217, 77, 34, 232, 106, 50, 168, 82, 76, 146, 67, 106, 171, 25, 132, 93, 45, 105],
    68: [0, 247, 159, 223, 33, 224, 93, 77, 70, 90, 160, 32, 254, 43, 150, 84, 101, 190, 205, 133, 52, 60, 202, 165, 220, 203, 151, 93, 84, 15, 84, 253, 173, 160, 89, 227, 52, 199, 97, 95, 231, 52, 177, 41, 125, 137, 241, 166, 225, 118, 2, 54, 32, 82, 215, 175, 198, 43, 238, 235, 27, 101, 184, 127, 3, 5, 8, 163, 238],
}
