/* Thor Server Project Copyright 2008 Joe Hegarty This file is part of The Thor Server Project. The Thor Server Project is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The Thor Server Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with The Thor Server Project. If not, see . */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ThorServer.Utilities { public static class Base64Encoding { public static string EncodeInt(int value, int length) { StringBuilder stack = new StringBuilder(length); for (int x = 1; x <= length; x++) { int offset = 6 * (length - x); byte val = (byte)(64 + (value >> offset & 0x3f)); stack.Append((char)val); } return stack.ToString(); } public static int DecodeInt(string strVal) { char[] val = strVal.ToCharArray(); int intTot = 0; int y = 0; for (int x = (val.Length - 1); x >= 0; x--) { int intTmp = (int)(byte)((val[x] - 64)); if (y > 0) { intTmp = intTmp * (int)(Math.Pow(64, y)); } intTot += intTmp; y++; } return intTot; } } }