You've already forked amazing-qr
mirror of
https://github.com/x-hw/amazing-qr.git
synced 2025-07-13 01:20:29 +02:00
complete ecc
This commit is contained in:
2
draw.py
2
draw.py
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
# test:
|
||||||
m1 = [[1]*7+[0]*7+[1]*7,
|
m1 = [[1]*7+[0]*7+[1]*7,
|
||||||
[1,0,0,0,0,0,1]+[0]*7+[1,0,0,0,0,0,1],
|
[1,0,0,0,0,0,1]+[0]*7+[1,0,0,0,0,0,1],
|
||||||
[1,0,1,1,1,0,1]+[0]*7+[1,0,1,1,1,0,1],
|
[1,0,1,1,1,0,1]+[0]*7+[1,0,1,1,1,0,1],
|
||||||
@ -41,4 +42,5 @@ def draw_qrcode(qrmatrix):
|
|||||||
pic.save('qrcode.jpg')
|
pic.save('qrcode.jpg')
|
||||||
pic.show()
|
pic.show()
|
||||||
|
|
||||||
|
# test:
|
||||||
draw_qrcode(m1)
|
draw_qrcode(m1)
|
50
ecc.py
50
ecc.py
@ -2,31 +2,54 @@
|
|||||||
|
|
||||||
#GP: Generator Polynomial, MP: Message Polynomial
|
#GP: Generator Polynomial, MP: Message Polynomial
|
||||||
# test:
|
# test:
|
||||||
GP = [0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45]
|
GP_list = {
|
||||||
|
7: [0, 87, 229, 146, 149, 238, 102, 21],
|
||||||
|
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],
|
||||||
|
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],
|
||||||
|
23: [0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 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]
|
||||||
|
}
|
||||||
|
|
||||||
#DC: Data Codewords, ECC: Error Correction Codewords
|
#DC: Data Codewords, ECC: Error Correction Codewords
|
||||||
def get_ECC(DC, ECC_num):
|
def get_ECC(DC, ECC_num):
|
||||||
po2 = get_power_of_2_list()
|
GP = GP_list[ECC_num]
|
||||||
log = get_log_list(po2)
|
|
||||||
|
|
||||||
# ..... get the correct GP according to ECC_num
|
|
||||||
|
|
||||||
remainder = DC
|
remainder = DC
|
||||||
for i in range(len(DC)):
|
for i in range(len(DC)):
|
||||||
remainder = divide(remainder, GP)
|
remainder = divide(remainder, *GP)
|
||||||
return remainder
|
return remainder
|
||||||
|
|
||||||
def divide(MP, GP):
|
def divide(MP, *GP):
|
||||||
|
po2 = get_power_of_2_list()
|
||||||
|
log = get_log_list(po2)
|
||||||
|
GP = list(GP)
|
||||||
|
for i in range(len(GP)):
|
||||||
|
GP[i] += log[MP[0]]
|
||||||
|
if GP[i] > 255:
|
||||||
|
GP[i] %= 255
|
||||||
|
GP[i] = po2[GP[i]]
|
||||||
|
|
||||||
|
return XOR(MP, GP)
|
||||||
|
|
||||||
|
|
||||||
|
def XOR(MP, GP):
|
||||||
a = len(MP) - len(GP)
|
a = len(MP) - len(GP)
|
||||||
if a < 0:
|
if a < 0:
|
||||||
MP += [0] * (-a)
|
MP += [0] * (-a)
|
||||||
elif a > 0:
|
elif a > 0:
|
||||||
GP += [0] * a
|
GP += [0] * a
|
||||||
|
|
||||||
log(MP[0])
|
remainder = []
|
||||||
|
for i in range(1, len(MP)):
|
||||||
def XOR():
|
remainder.append(MP[i]^GP[i])
|
||||||
pass
|
return remainder
|
||||||
|
|
||||||
def get_power_of_2_list():
|
def get_power_of_2_list():
|
||||||
po2 = [1]
|
po2 = [1]
|
||||||
@ -42,6 +65,3 @@ def get_log_list(po2):
|
|||||||
for i in range(255):
|
for i in range(255):
|
||||||
log[po2[i]] = i
|
log[po2[i]] = i
|
||||||
return log
|
return log
|
||||||
|
|
||||||
# test:
|
|
||||||
dc = '32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236, 17, 236, 17'
|
|
||||||
|
Reference in New Issue
Block a user