Friday, June 3, 2011

URL shortener algorithm

Here is a simple hashing algorithm that generates a short string for a given ID. This can be used for example in an URL shortener where you store the full URL under an ID and use this algorithm to generate a sort string to reference that ID.

more on that on stackoverflow or on


  1. Thanks for sharing this, it appears is exactly what I'm looking for. However, I would like to pass a 32 character alpha-numeric string, get a shortened string, and then convert the shortened string back to the original. This example returns numbers that I'm not sure what they mean. How can I use this to get strings matching the criteria I listed above?

  2. Did you know you can create short urls with AdFly and make cash for every click on your shortened urls.