Is there an algorithm that will yield the same hash for two numbers, no matter what order they are in?
For example, hashing 3268 and 2642 should yield the same result as hashing 2642 and 3268.
Is this possible?
Of course, XOR does that.
3268^2642 == 2642^3268
There's a lot more (addition, multiplication, basically any commutative operation), but XOR is usually used for hashing anyway (because it's easy to "unhash").
Hash the two numbers separately (using an integer-to-integer hash of your choice), and then either add or xor the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With