How to generate checksum using micropython?
How to generate checksum using micropython?
How to generate checksum using micropython?
Re: How to generate checksum using micropython?
Which checksum algorithm do you need to use? CRC32?
Re: How to generate checksum using micropython?
With thanks for your attention
I do not want CRC Check.
I don't know the check algorithm. but i have very example:
"String" => Checksum
"ABC"=>85
"CBA"=>85
"A"=>84
"BBB"=>87
"CCC"=>86
"C"=>86
"123"=>37
"321"=>37
"213"=>37
"132"=>37
I do not want CRC Check.
I don't know the check algorithm. but i have very example:
"String" => Checksum
"ABC"=>85
"CBA"=>85
"A"=>84
"BBB"=>87
"CCC"=>86
"C"=>86
"123"=>37
"321"=>37
"213"=>37
"132"=>37
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to generate checksum using micropython?
That is a very poor algorithm. I can't deduce how it works from those examples but maybe someone else can.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: How to generate checksum using micropython?
Yes, that looks like some variant of an LRC. Do you also have an example for two identical characters, like "AA"?
Re: How to generate checksum using micropython?
It's
Code: Select all
def checksum(msg):
v = 21
for c in msg:
v ^= ord(c)
return v
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to generate checksum using micropython?
So it is! Nice one
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: How to generate checksum using micropython?
jimmo wrote: ↑Wed Sep 04, 2019 7:00 amIt's
Code: Select all
def checksum(msg): v = 21 for c in msg: v ^= ord(c) return v
That's great, thank you
how did you know?
How did you find
Thank you again.
Re: How to generate checksum using micropython?
There 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.