So when exploring hash functions I noticed the following equation:
((129*N)^prev)%256 = ((129*N)%256)^prev
For any number N, prev
between 0 and 255. Basically you can drag the mod operation out without changing the result, and it only works for number 129. Can somebody maybe tell me what is so special about 129?
This is easier to see if you interpret that modulo by 256 as bitwise AND by 255, or in other words, keeping only the least significant 8 bits.
Clearly the XOR does not make information from the higher bits travel to the lower bits (actually there's no traveling in either direction), so whatever happens "up there" cannot make any difference for the low bits. It could have made a difference for the high bits (which the XOR could set, and then depending on whether the AND happens first or second, those bits are respectively kept set or reset), but by assumption that cannot happen here.
Algebraically, AND distributes over XOR, so
(a ^ b) & c =
& distributes over ^
(a & c) ^ (b & c)
And we have that b & c = b
because c
is 255 and b
is between 0 and 255, so
(a & c) ^ (b & c) =
by assumptions
(a & c) ^ b
This is not related to the multiplication, it could have been literally anything, I've just called that part a
here.