'Reversible folding function?

I have a set of numbers (generated as numeric strings) of variable size and I would like to store them in a hash table having both as key and value unsigned 32-bits integer. Of course the keys and values to hash can be larger (even larger than 64 bits), so before inserting them I need to do some sort of folding to reduce their size. However, I am not aware of any reversible way to fold keys - I thought about hashing, but this is usually not reversible. What are easy functions to use to transform a long string into a shorter one and the opposite way around in order to retrieve the original value?



Solution 1:[1]

It is not possible to map 64-bit values into 32-bit values in a reversible way. There are only 4294967296 possible 32-bit values, but you could have 4294967297 different 64-bit values in your table. Then, two of them would have to be the same (this is called the Pigeonhole Principle) and that same value would have to map to two different 64-bit values when you reversed it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jarod42