I’m looking for an algorithm – or should I better say: encoding? – to compress integer numbers to short string IDs like URL shorteners use: http://goo.gl/0puu
Url safe base 64 comes close to it, but maybe there is something better.
Requirements:
- as short as possible
- url safe
“yi_H” called base64 “perfect” and after a bit more research I came to the same conclusion, since only the following characters could be used in URLs without worry:
Thats 66 characters, whereas base64 only uses 64 characters. The two more possible characters wouldn’t be practical because 66 is not based on 2.
Conclusion: URL safe base64 (offered as part of Apache Commons for example) is perfect for short IDs.