using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Security.Cryptography; using System.Windows.Forms; namespace Blizzard { public static class HabboEncode { // Codificación Base64-VL64 de HabboHotel, diseñada por Jeax, Estructura de Nillus // Blizzard #region Base64 public static string encodeB64(int value, int length) { string stack = ""; for (int x = 1; x <= length; x++) { int offset = 6 * (length - x); byte val = (byte)(64 + (value >> offset & 0x3f)); stack += (char)val; } return stack; } public static string encodeB64(string Val) { int value = Val.Length; int length = 2; string stack = ""; for (int x = 1; x <= length; x++) { int offset = 6 * (length - x); byte val = (byte)(64 + (value >> offset & 0x3f)); stack += (char)val; } return stack; } public static int decodeB64(string Val) { char[] val = Val.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; } #endregion #region VL64 public static string encodeVL64(int i) { byte[] wf = new byte[6]; int pos = 0; int startPos = pos; int bytes = 1; int negativeMask = i >= 0 ? 0 : 4; i = Math.Abs(i); wf[pos++] = (byte)(64 + (i & 3)); for (i >>= 2; i != 0; i >>= 6) { bytes++; wf[pos++] = (byte)(64 + (i & 0x3f)); } wf[startPos] = (byte)(wf[startPos] | bytes << 3 | negativeMask); System.Text.ASCIIEncoding encoder = new ASCIIEncoding(); string tmp = encoder.GetString(wf); return tmp.Replace("\0", ""); } public static int decodeVL64(string data) { return decodeVL64(data.ToCharArray()); } public static int decodeVL64(char[] raw) { try { int pos = 0; int v = 0; bool negative = (raw[pos] & 4) == 4; int totalBytes = raw[pos] >> 3 & 7; v = raw[pos] & 3; pos++; int shiftAmount = 2; for (int b = 1; b < totalBytes; b++) { v |= (raw[pos] & 0x3f) << shiftAmount; shiftAmount = 2 + 6 * b; pos++; } if (negative) v *= -1; return v; } catch { return 0; } } #endregion } public static class sHabboEncoding { // Secondary modification, try some things... public static String vl64Encode(int i) { byte[] wf = new byte[6]; int pos = 0; int startPos = pos; int bytes = 1; int negativeMask = i >= 0 ? 0 : 4; i = Math.Abs(i); wf[pos++] = (byte)(64 + (i & 3)); for (i >>= 2; i != 0; i >>= 6) { bytes++; wf[pos++] = (byte)(64 + (i & 0x3f)); } wf[startPos] = (byte)(wf[startPos] | bytes << 3 | negativeMask); string tmp = Encoding.Default.GetString(wf); //encoder.GetString(wf); return tmp.Replace("\0", ""); } public static int vl64Decode(String data) { char[] chars; chars = data.ToCharArray(); return vl64Decode(chars); } public static int vl64Decode(char[] raw) { try { int pos = 0; int v = 0; bool negative = (raw[pos] & 4) == 4; int totalBytes = raw[pos] >> 3 & 7; v = raw[pos] & 3; pos++; int shiftAmount = 2; for (int b = 1; b < totalBytes; b++) { v |= (raw[pos] & 0x3f) << shiftAmount; shiftAmount = 2 + 6 * b; pos++; } if (negative == true) v *= -1; return v; } catch (Exception e) { return 0; } } public static String b64Encode(int i) { try { String s = ""; for (int x = 1; x <= 2; x++) s += (char)((byte)(64 + (i >> 6 * (2 - x) & 0x3f))); return s; } catch (Exception e) { BlizzardSystem.WriteLine(e.ToString()); return ""; } } public static int b64Decode(string s) { try { char[] val = s.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; } catch (Exception e) { BlizzardSystem.WriteLine(e.ToString()); return 0; } } } }