You declared packet as a printable representation of a message:
packet = '0x8d 0x1e 0x19 0x1b 0x83 0x00 0x01 0x01 0x00 0x00 0x00 0x4b 0x00 0x00'
therefore, your current message is not [0x8d, 0x1e, ..., 0x00] , but ['0', 'x', '8', 'd', ..., '0'] . So, the first step is to fix it:
packet = '0x8d 0x1e 0x19 0x1b 0x83 0x00 0x01 0x01 0x00 0x00 0x00 0x4b 0x00 0x00' packet = [chr(int(x, 16)) for x in packet.split(' ')]
Or you could consider coding to be βrightβ from the start:
packet = '\x8d\x1e\x19\x1b\x83\x00\x01\x01\x00\x00\x00\x4b\x00\x00'
At this point, we can xor a member by member:
checksum = 0 for el in packet: checksum ^= ord(el) print checksum, hex(checksum), chr(checksum)
the checksum that I get is 0x59 , not 0xc2 , which means that you either calculated the wrong one or the original message is not the one you specified.
source share