Havok-N Checksum algorithm
Checksum algorithm based on Fletcher-16 & Adler-32 plus an optional iterative hash function, by Lucy Havok <naln1@peepee.party>.
Forwhat?
Fletcher's Checksum algorithm is way overengineered. Adler had the right idea with many of the tweaks he made to simplify and solidify the algorithm. However, I preferred the idea of having a user-defined arbitrary shift/modulo (as I see no reason to disallow that), but also make sure that the modulo is always prime so as to reduce checksum collision.
But mostly, I often prototype with PHP. I started with Fletcher-16 and that seemed to work fine. And then I tried to implement Fletcher-32 and PHP was acting a bit weird about it. And then I tried to implement Fletcher-64 and noticed a glaring flaw in the concept of calculating sums against chunks of data greater than one byte (mostly in the effectively undefined behavior of what happens if you have an odd number of bytes). I went to bed, with the intention to fix whatever silliness was going on in the morning. However, I could not fall asleep as I continued to think about how unreasonable Fletcher-16 and -32 are1, so I had to get up, turn my Kettle2 back on, and solve all my problems with Fletcher's overengineered and poorly-defined algorithm.
Table comparison
Fletcher | Adler | Havok | |
---|---|---|---|
Word Size | 8b | 16b | 32b | 8b | 8b |
Bits | 16 | 32 | 64 | 32 | arbitrary |
Modulo | 28 | 216 | 232 | 65,521 | nearest prime under 2Bits |
Shift | 8 | 16 | 32 | 16 | Bits/2 |
Iterative Function | no | no | optional, arbitrary № iterations |
Implementations
- PHP (reference)
- JavaScript
TODO Mathematical function
Can you read PHP or JS? Do you know how to write mathematical functions? Please write this mathematical function for me. I don't wanna learn how.
- ^ https://ak.angelstrapped.com/notice/AotstBVPE0YXPtP1DE
- ^ An affectionate nickname for a 2011 MacMini that sounds like a boiling electric kettle when its fan spins up