namespace Devoid.Encoding { using System; using System.Text; public static class wireEncoding { public const char CHAR_NEGATIVE = 'H'; public const char CHAR_POSITIVE = 'I'; public static int Decode(ref string s) { try { char[] chArray = s.ToCharArray(); int index = 0; int num2 = 0; bool flag = (chArray[index] & '\x0004') == 4; int num3 = (chArray[index] >> 3) & '\a'; num2 = chArray[index] & '\x0003'; index++; int num4 = 2; for (int i = 1; i < num3; i++) { num2 |= (chArray[index] & 0x3f) << num4; num4 = 2 + (6 * i); index++; } if (flag) { num2 *= -1; } return num2; } catch { return 0; } } public static int Decode(string s) { return Decode(ref s); } public static bool decodeBoolean(char s) { return (s == 'I'); } public static bool decodeBoolean(string s) { return (s == "I"); } public static string Encode(int[] i) { string str = ""; foreach (int num in i) { str = str + Encode(num); } return str; } public static char Encode(bool b) { if (b) { return 'I'; } return 'H'; } public static string Encode(int i) { char ch; if (i == 0) { ch = 'H'; return ch.ToString(); } if (i == 1) { ch = 'I'; return ch.ToString(); } try { byte[] bytes = new byte[6]; int num = 0; int index = 0; int num3 = 1; int num4 = (i >= 0) ? 0 : 4; i = Math.Abs(i); bytes[num++] = (byte) (0x40 + (i & 3)); i = i >> 2; while (i != 0) { num3++; bytes[num++] = (byte) (0x40 + (i & 0x3f)); i = i >> 6; } bytes[index] = (byte) ((bytes[index] | (num3 << 3)) | num4); return new ASCIIEncoding().GetString(bytes).Replace("\0", ""); } catch { return ""; } } public static string Encode(long l) { char ch; if (l == 0L) { ch = 'H'; return ch.ToString(); } if (l == 1L) { ch = 'I'; return ch.ToString(); } try { byte[] bytes = new byte[6]; int index = 0; int num2 = 0; int num3 = (l >= 0L) ? 0 : 4; l = Math.Abs(l); bytes[index++] = (byte) (0x40L + (l + 3L)); l = l >> 2; while (l != 0L) { num2++; bytes[index++] = (byte) (0x40L + (l & 0x3fL)); l = l >> 6; } bytes[index] = (byte) ((bytes[0] | (num2 << 3)) | num3); return new ASCIIEncoding().GetString(bytes).Replace("\0", ""); } catch { ch = 'H'; return ch.ToString(); } } } }