const int BITMASK = (1 << BITCOUNT/2) - 1;
static uint roundFunction(uint number) {
return (((number ^ 47894) + 25) << 1) & BITMASK;
static uint crypt(uint number) {
uint left = number >> (BITCOUNT/2);
uint right = number & BITMASK;
for (int round = 0; round < 10; ++round) {
left = left ^ roundFunction(right);
uint temp = left; left = right; right = temp;
return left | (right << (BITCOUNT/2));
const string ALPHABET= "AG8FOLE2WVTCPY5ZH3NIUDBXSMQK7946";
static string couponCode(uint number) {
StringBuilder b = new StringBuilder();
for (int i=0; i<6; ++i) {
b.Append(ALPHABET[(int)number&((1 << 5)-1)]);
static uint codeFromCoupon(string coupon) {
for (int i = 0; i < 6; ++i)
n = n | (((uint)ALPHABET.IndexOf(coupon[i])) << (5 * i));
public static void Main()
Console.WriteLine(ALPHABET.Length.ToString());
Console.WriteLine("Hello World");
var test = codeFromCoupon("SAVESA");
var couponTest = couponCode(crypt(1));
Console.WriteLine(test.ToString());
Console.WriteLine(couponTest);