jablotron80
jablotron80 copied to clipboard
Simplify checksum code
Hi, the checksum code used in the original Windows application is pretty simple:
def checksum(msg):
sum = 0x7f
for byte in msg:
for j in range(8):
sum <<= 1
if (byte & 0x80) == 0x80:
sum += 1
if (sum & 0x80) == 0x80:
sum ^= 0xa3
byte <<= 1
return sum
# binary message without trailing 0xFF
if len(msg) > 1 and checksum(msg) != 0:
raise SomeCheckSumError