public static void Main()
long number = 12349874529768521;
string result = BaseN.Encode(number);
number = BaseN.Decode(result);
Console.WriteLine(number);
Console.WriteLine(result);
public static class BaseN
private const string CharList = "0123456789abcdefghijklmnopqrstuvwxyz";
public static String Encode(long input)
throw new ArgumentOutOfRangeException("input", input, "input cannot be negative");
var result = new System.Collections.Generic.Stack<char>();
result.Push(CharList.ToCharArray()[input % CharList.Length]);
input /= CharList.Length;
return new string (result.ToArray());
public static long Decode(string input)
long result = 0, pos = 0;
foreach (char c in input.Reverse())
result += CharList.IndexOf(c) * (long)Math.Pow(CharList.Length, pos);