2 ms·
I can easily meet those literal requirements with a function that is total garbage. 1. Take all the input bits and XOR them together. Now we have a value which
by kazinator 3y ago
I can easily meet those literal requirements with a function that is total garbage.
1. Take all the input bits and XOR them together. Now we have a value which flips between 0 and 1 every time we change a single bit of the input.
2. Use this value as an index into the sequence { 0xFFFFFFFF, 0xF0F0F0F0 }
Now we get 50% of the bits flipping when we change a single bit of the input.
- dahart 3y agoThat doesn’t meet the Avalanche Effect requirements. The requirement is that 50% of the bits change independently (on average) whenever an input bit changes. In other words, the output bit values need to be both random and uniformly distributed relative to every input bit. https://en.wikipedia.org/wiki/Avalanche_effect#Bit_independence_criterion https://en.wikipedia.org/wiki/Avalanche_effect#Bit_independe...
- marginalia_nu 3y agoHold your plucked chicken, Diogenes. Note the "evenly distributed" requirement. This is not. But in general, sure, there's a lot of hash functions that aren't great. f(x)=x is one, that's actually even seen in the wild. Java's Integer class does that for its hashCode() function, and it even does a passable job of indexing a hash table.