I need to shorten a unique string ID to a maximum of 12 characters. The ID could be longer or shorter than 12 characters before the conversion but its length has to be shorter or equal to 12 after the conversion. It could also be represented by int or even float after conversion.
Using this function on the same string should always return the same shortened ID. However, it should never return the same value for two different IDs.
(I know, theoretically, this is not possible with a fixed number of output chars, but if it's reasonably unlikely to produce the same result twice, that's okay, because I am only dealing with a few thousand IDs.)
I was thinking of a hash function, but you can't really specify the length of the return value. A benefit would be reversibility of the function, as a URL shortener but I can also create a dictionary for that purpose.
Any hints to an algorithm that works in this scenario are appreciated!