Pinject
Pinject copied to clipboard
Checksum function does not work for odd-sized data
Checksum function does not work for odd-sized data. Here is the one I use: def checksum(data): s = 0 n = len(data) % 2 if n: data = data + '\0' for i in range(0, len(data)-n, 2): s+= ord(data[i]) + (ord(data[i+1]) << 8) while (s >> 16): print("s >> 16: ", s >> 16) s = (s & 0xFFFF) + (s >> 16) print("sum:", s) s = ~s & 0xffff return s
yeah,here is the bug:
if n: s += ord(data[i+1])
you should replace 1 with 2.