namespace Devoid.Encoding { using System; using System.Collections.Generic; public static class base64Encoding { public static int Decode(string s) { return Decode(s.ToCharArray()); } public static string base64Encode(string data) { try { byte[] encData_byte = new byte[data.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(data); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch (Exception e) { throw new Exception("Error in base64Encode" + e.Message); } } public static int Decode(byte[] ba) { int num = 0; int num2 = 0; for (int i = 1; i >= 0; i--) { int num4 = ba[i] - 0x40; if (num2 > 0) { num4 *= (int) Math.Pow(64.0, (double) num2); } num += num4; num2++; } return num; } public static int Decode(char[] chr) { return Decode(new byte[] { (byte) chr[0], (byte) chr[1] }); } public static string Encode(int i) { try { string str = ""; for (int j = 1; j <= 2; j++) { str = str + ((char) ((byte) (0x40 + ((i >> (6 * (2 - j))) & 0x3f)))); } return str; } catch { return ""; } } public static string getParameter(string s, int parameterLocation) { try { for (int i = 0; s.Length > 0; i++) { int length = Decode(s.Substring(0, 2)); if (i == parameterLocation) { return s.Substring(2, length); } s = s.Substring(length + 2); } } catch { } return ""; } public static string[] getParameters(string messageContent) { List list = new List(); try { while (messageContent.Length > 0) { int length = Decode(messageContent.Substring(0, 2)); list.Add(messageContent.Substring(2, length)); messageContent = messageContent.Substring(2 + length); } } catch { } return list.ToArray(); } public static string getStructuredParameter(string s, int paramID) { try { int num = 0; float num2 = s.Length / 4; while (num <= num2) { int num3 = Decode(s.Substring(0, 2)); int length = Decode(s.Substring(2, 2)); if (num3 == paramID) { return s.Substring(4, length); } s = s.Substring(length + 4); } } catch { } return ""; } } }