public static void Main()
var shortURL = toShortURL(id);
Console.WriteLine("http://short.url/{0}", shortURL);
Console.WriteLine("ID: {0}", fromShortURL(shortURL));
static string toShortURL(int n)
string shortURL = string.Empty;
string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuilder sb = new StringBuilder();
var c = sb.ToString().ToCharArray();
shortURL = new string(c);
static int fromShortURL(string shortURL)
for (int i = 0; i < shortURL.Length; ++i)
if ('a' <= shortURL[i] && shortURL[i] <= 'z')
id = id*62 + shortURL[i] - 'a';
if ('A' <= shortURL[i] && shortURL[i] <= 'Z')
id = id*62 + shortURL[i] - 'A' + 26;
if ('0' <= shortURL[i] && shortURL[i] <= '9')
id = id*62 + shortURL[i] - '0' + 52;