This commit is contained in:
Cort Buffington 2016-10-02 08:16:13 -05:00
parent 0822cb5503
commit 0293f6d5e6
2 changed files with 13 additions and 5 deletions

View File

@ -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
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))

6
qr.py
View File

@ -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