Pinject icon indicating copy to clipboard operation
Pinject copied to clipboard

Checksum function does not work for odd-sized data

Open ahahahahahah opened this issue 10 years ago • 1 comments

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

ahahahahahah avatar Apr 19 '15 16:04 ahahahahahah

yeah,here is the bug: if n: s += ord(data[i+1]) you should replace 1 with 2.

shyixiu avatar Mar 05 '17 08:03 shyixiu