I desperately need a hash / compression function that is suited to shorten text.
The context is this: I want to bring order and sort my box with hundreds of charging adapters (duh). After I determined for each one to what ever it belongs to, I want to label it accordingly.
Why don´t I just enumerate them? I have tried this in the past and it didn´t work out well for me. I forgot where the file is that mapped numbers, and also the 'order' didn´t make any sense.
What I want to do: have a function f that would do something like e.g. "Nikon CoolPix S3300" -> a9cd81d2, so a function that shortens a string that can contain alphanumeric letters and outputs a shorter (hexanumerical) string that could also decoded / reversed later to find out what was the original input.
If I wanted to simply encode the string, the output would always be longer. In ASCII or UTF-8, a single character would then by 1 byte each at least, meaning two hexadecimal numbers per letter. The result is that the output is not shorter but much longer.
I also considered hash functions. However, I´m unsure about this because of these factors:
- Most hash functions have a quite long output that wouldn´t fit onto my labels, e.g. 128 bits, which is 32 hex digits.
- Cryptographic hash functions aren´t intended to be reversed. I am aware that some of the old hash functions like e.g. md5 can be cracked, but I want something that could be decoded back in a matter of seconds, even on a CPU.
So in the end, I am looking for something with these properties:
- Is fast to compute in both directions (hashing/reversing or encoding decoding)
- Has outputs of equal sizes, like hash functions
- The outputs are short, e.g. 4 bytes
- Despite short outputs, the collision probability of natural language strings is generally small
- Restoring / decoding the original string is accurate. If collisions exist, it is likely to get the original input string
Does a hash / encoding algorithm exist that can fulfill these needs?