const int propertyId = 1223;
public static void Main()
Console.WriteLine("ShortCode: {0}", ShortCode.ToShortCode(propertyId));
private const string CharacterSet = "B3C7DFG6HJ5KM2NP9QRSTV4WX8YZ";
private const int BitsInLong = 64;
private const short DefaultLength = 4;
private const int BaseAmount = 21952;
public static int ToInteger(string shortCode)
if (shortCode.Length < DefaultLength) return 0;
var reversed = shortCode.ToUpper().ToArray();
for (var i = reversed.Length - 1; i >= 0; i--)
var digit = CharacterSet.IndexOf(reversed[i]);
if (digit == -1) return 0;
sum += digit * multiplier;
multiplier *= CharacterSet.Length;
return Math.Max(sum - BaseAmount, 0);
public static string ToShortCode(int integer)
if (integer <= 0) return "";
var code = integer + BaseAmount;
var index = BitsInLong - 1;
long currentNumber = Math.Abs(code);
var charArray = new char[BitsInLong];
while (currentNumber != 0)
var remainder = (int) (currentNumber % CharacterSet.Length);
charArray[index--] = CharacterSet[remainder];
currentNumber = currentNumber / CharacterSet.Length;
var result = new string(charArray, index + 1, BitsInLong - index - 1);