How to generate checksum using micropython?
Re: How to generate checksum using micropython?
This is a very good explanation.
Re: How to generate checksum using micropython?
jimmo wrote: ↑Sat Sep 07, 2019 12:18 amThere are three clues:
- Ordering doesn't matter. (e.g. ABC == CBA) so it's likely that the checksum is processed byte at a time.
- Making it longer (especially repeating, and even more so, triple repeats) doesn't change the result dramatically. Not likely to be adding the bytes together, like many other simple checksums. This leaves XOR as the likely candidate. Triple AAA giving the same result as single A is a good confirmation of XOR.
- A, B, C checksums clustered around a different value to 1, 2, 3 based one. Means that it's possibly based on the ascii value (i.e. ord). Also A and C going to values two apart (84 and 86) suggests there's no non-linear change to the byte value before whatever accumulation happens.
XOR-based ones often start with a non-zero value, this is so that checksumming a message of NUL bytes (i.e. all zeros) doesn't also give zero as the result.
At that point it's just algebra to solve for the starting value -- ord('A') ^ 84 --> 21. Check with 21^ord('C') --> 86, and 21^ord('1')^ord('2')^ord('3') --> 37.
Very good
Very clever
Well done
-
- Posts: 84
- Joined: Mon Mar 20, 2017 10:22 pm
Re: How to generate checksum using micropython?
Reviewing this post years later and I wish I could give a standing ovation haha. That was an impressive analysis on so little input data.