diff --git a/golay.py b/golay.py index 0d6b110..4f4a19c 100755 --- a/golay.py +++ b/golay.py @@ -225,7 +225,7 @@ def decode_2087(_data): def encode_2087(_data): value = data[0] - cksum = ENCODING_TABLE_2087[value] + cksum = ENCODE_2087[value] data[1] = cksum & 0xFF data[2] = cksum >> 8 return _data @@ -238,4 +238,12 @@ def encode_2087(_data): if __name__ == '__main__': from binascii import b2a_hex as h - from time import time \ No newline at end of file + from time import time + + # For testing the code + def print_hex(_list): + print('[{}]'.format(', '.join(hex(x) for x in _list))) + + data = [0x12,0x23,0x45] + + print_hex(encode_2087(data)) \ No newline at end of file diff --git a/qr.py b/qr.py index 8a16b17..ca5dc0c 100755 --- a/qr.py +++ b/qr.py @@ -72,14 +72,14 @@ def get_synd_1576(_pattern): def encode(_data): value = (_data[0] >> 1) & 0x7F cksum = ENCODE_1676[value] - data[0] = cksum >> 8 - data[1] = cksum & 0xFF + _data[0] = cksum >> 8 + _data[1] = cksum & 0xFF return _data def decode(_data): code = (_data[0] << 7) + (_data[1] >> 1) syndrome = get_synd_1576(code) - error_pattern = DECODING_TABLE_1576[syndrome] + error_pattern = DECODE_1576[syndrome] code ^= error_pattern return code >> 7