I need to convert user db id or username (or whatever else is unique for each account) to an unique 3-5 character string with characters and/or numbers.
Example: id 12481 would look like HJ28.
It should work both ways, so when HJ28 is given I can convert it back to the number. What would be the easiest way of doing this?
If your id is numeric, you can pass it to base 255 and store the chars. If the chars are too weird, you can use a base 36 (letters + numbers) and it will reduce the amount of characters finally needed.
The idea is to use the same as converting the number "10" (two chars) in decimal to hex will give you "a" (one char). Using base 36 or 255 will "compress" a lot your id.
12481 <-> A2D8A maybe ? Or you can choose anything else.