I need a small program that can calculate the checksum from a user input.
Unfortunately, all I know about the checksum is that it’s xor all data in packet.
I have tried to search the net for an example without any luck.
I know if I have a string: 41,4D,02,41,21,04,02,02,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
This should result in a checksum of 6A.
Hopefully someone could help me. If someone has an example writen in Python 3, could also work for me
If I understand “xor all data in packet” correctly, then you should do something like this:
The idea is to establish a variable initialized to
0and then xor all elements of the packet with it while storing the result of the operation in the same variable on each step.EDIT: edited the answer to provide complete working example (far from perfect, but works).
Usage: enter bytes as required, once you are finished with input, enter anything invalid, for example
q(cannot be a hexadecimal number). You will get the checksum printed.