def errorCorrect(info): groups = [[], []] block_map = data_maps.blockMap() byte_array = list(info["byte_array"]) blocks_in_group_1 = block_map["%s-%s" % (info["version"], info["error_correction_level"])][2] blocks_in_group_2 = block_map["%s-%s" % (info["version"], info["error_correction_level"])][4] for i in range(blocks_in_group_1): groups[0].append([]) for i in range(blocks_in_group_2): groups[1].append([]) codewords_in_group_1_block = block_map["%s-%s" % (info["version"], info["error_correction_level"])][3] codewords_in_group_2_block = block_map["%s-%s" % (info["version"], info["error_correction_level"])][5] for block in groups[0]: for i in range(codewords_in_group_1_block): block.append(byte_array[0]) del(byte_array[0]) for block in groups[1]: for i in range(codewords_in_group_2_block): block.append(byte_array[0]) del(byte_array[0]) for byte in info["byte_array"]: print int(byte, 2)
def breakUpAndPad(info): block_map = data_maps.blockMap() required_bits = block_map["%s-%s" % (info["version"], info["error_correction_level"])][0] * 8 byte_string = info["mode_indicator"] + info["character_count_indicator"] for byte in info["encoded_text"]: byte_string += byte terminator = "" for i in range(required_bits - len(byte_string)): if i > 3: break terminator += "0" byte_string += terminator info["terminator"] = terminator info["required_bits"] = required_bits while len(byte_string) % 8 != 0: byte_string += "0" pad_byte_strings = ["11101100", "00010001"] pad_bytes = [] for i in range((required_bits - len(byte_string)) / 8): byte_string += pad_byte_strings[(i + 2) % 2] pad_bytes.append(pad_byte_strings[(i + 2) % 2]) info["pad_bytes"] = pad_bytes info["byte_string"] = byte_string info["byte_array"] = splitIntoBytes(byte_string) errorCorrect(info)
def errorCorrect(info): groups = [[], []] block_map = data_maps.blockMap() byte_array = list(info["byte_array"]) blocks_in_group_1 = block_map["%s-%s" % (info["version"], info["error_correction_level"])][2] blocks_in_group_2 = block_map["%s-%s" % (info["version"], info["error_correction_level"])][4] for i in range(blocks_in_group_1): groups[0].append([]) for i in range(blocks_in_group_2): groups[1].append([]) codewords_in_group_1_block = block_map["%s-%s" % (info["version"], info["error_correction_level"])][3] codewords_in_group_2_block = block_map["%s-%s" % (info["version"], info["error_correction_level"])][5] for block in groups[0]: for i in range(codewords_in_group_1_block): block.append(byte_array[0]) del (byte_array[0]) for block in groups[1]: for i in range(codewords_in_group_2_block): block.append(byte_array[0]) del (byte_array[0]) for byte in info["byte_array"]: print int(byte, 2)