Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ResMan.Classes.KeyCodeLibrary
- using System;
- using System.Text;
- internal static class KeyCodeLibrary
- {
- private const long S11 = 7L;
- private const long S12 = 12L;
- private const long S13 = 17L;
- private const long S14 = 22L;
- private const long S21 = 5L;
- private const long S22 = 9L;
- private const long S23 = 14L;
- private const long S24 = 20L;
- private const long S31 = 4L;
- private const long S32 = 11L;
- private const long S33 = 16L;
- private const long S34 = 23L;
- private const long S41 = 6L;
- private const long S42 = 10L;
- private const long S43 = 15L;
- private const long S44 = 21L;
- public const string MyProductName = "ResManV131";
- public const string B32Map = "0123456789ABCDEFGHJKLMNPRSTVWXYZ";
- private const long OFFSET_4 = 4294967296L;
- private const long MAXINT_4 = 2147483647L;
- public static long ByteCounter;
- public static long[] State;
- public static byte[] ByteBuffer;
- public static string GenKeyString(string UserName, string ProdName, long F_Code)
- {
- string text = null;
- string text2 = null;
- char[] array = null;
- long num = 0L;
- byte b = 0;
- byte b2 = 0;
- byte b3 = 0;
- byte b4 = 0;
- text = UserName.ToLower() + ProdName.ToLower();
- text2 = DigestStrToHexStr(text);
- array = HexStrToBinStr(text2);
- num = (F_Code & 0xFFFF);
- b = (byte)(num & 0xFF);
- b2 = (byte)((num & 0xFF00) / 256 & 0xFF);
- char c = array[array.Length - 1];
- char c2 = array[array.Length - 2];
- b3 = (byte)c;
- b4 = (byte)c2;
- b3 = (byte)(b3 ^ b);
- b4 = (byte)(b4 ^ b2);
- char c3 = (char)b3;
- char c4 = (char)b4;
- string text3 = new string(array);
- text3 = text3.Substring(0, array.Length - 2);
- text3 = text3 + c4 + c3;
- text3 = text3.Substring(2, text3.Length - 2);
- string text4 = DigestStrToHexStr(text3);
- string str = text4.Substring(0, 2);
- string str2 = text4.Substring(text4.Length - 2, 2);
- string str3 = BinStrToHexStr(text3);
- return str + str2 + str3;
- }
- public static string Base32Enc(string StrIn)
- {
- byte b = 0;
- long num = 0L;
- byte b2 = 0;
- long num2 = 0L;
- long num3 = 0L;
- string text = null;
- string text2 = null;
- string text3 = null;
- int num4 = 0;
- int num5 = 0;
- text2 = "";
- text = StrIn;
- num2 = StrIn.Length * 8;
- num4 = (int)(num2 / 5);
- if (num2 % 5 != 0)
- {
- num4++;
- }
- num5 = StrIn.Length;
- num3 = 0L;
- b = 31;
- for (num = 0L; num < num4; num++)
- {
- b2 = (byte)text[text.Length - 1];
- b2 = (byte)((b2 & b) + 1);
- text3 = "0123456789ABCDEFGHJKLMNPRSTVWXYZ".Substring(b2 - 1, 1);
- text = MyShiftToRight(text, 5L);
- text2 = text3 + text2;
- }
- return text2;
- }
- public static string BinStrToHexStr(string StrIn)
- {
- string text = "";
- foreach (char value in StrIn)
- {
- string text2 = Convert.ToString(value, 16);
- if (text2.Length == 1)
- {
- text2 = "0" + text2;
- }
- text += text2;
- }
- return text;
- }
- public static bool ValidateKeyCode(string KeyCode, string UserName, string ProjName)
- {
- string text = "";
- string text2 = "";
- string text3 = "";
- string text4 = "";
- bool flag = false;
- if (KeyCode.Length == 32)
- {
- string text5 = new string(HexStrToBinStr(KeyCode));
- text = text5.Substring(text5.Length - 14, 14);
- string text6 = DigestStrToHexStr(text);
- text4 = text6.Substring(0, 2) + text6.Substring(text6.Length - 2, 2);
- text3 = KeyCode.Substring(0, 4);
- if (text3.ToUpper() == text4.ToUpper())
- {
- flag = true;
- }
- if (flag)
- {
- string sourceString = UserName.ToLower() + ProjName.ToLower();
- text2 = DigestStrToHexStr(sourceString);
- text = KeyCode.Substring(4, 24);
- text2 = text2.Substring(4, 24);
- }
- if (text.ToUpper() == text2.ToUpper())
- {
- flag = true;
- }
- }
- else
- {
- flag = false;
- }
- return flag;
- }
- public static string RemoveDashes(string StrIn)
- {
- return StrIn.Replace("-", "");
- }
- public static string Base32Dec(string StrIn)
- {
- int num = 0;
- byte b = 0;
- string text = null;
- string text2 = null;
- byte b2 = 0;
- long num2 = 0L;
- long num3 = 0L;
- try
- {
- num3 = StrIn.Length * 5;
- num2 = Convert.ToInt64(num3 / 8);
- for (num = 0; num < num2; num++)
- {
- text += '\0';
- }
- foreach (char value in StrIn)
- {
- b = Convert.ToByte("0123456789ABCDEFGHJKLMNPRSTVWXYZ".IndexOf(value));
- text = MyShift(text, 5L);
- char c = text[text.Length - 1];
- text = text.Substring(0, text.Length - 1);
- b2 = (byte)c;
- b2 = (byte)(b2 | b);
- c = (char)b2;
- text += c;
- byte b3 = (byte)text[text.Length - 2];
- }
- }
- catch (Exception)
- {
- return "";
- }
- return text;
- }
- public static string MyShift(string StrIn, long Bits)
- {
- string text = "";
- byte b = 0;
- long num = 0L;
- string text2 = null;
- num = Convert.ToInt64(Bits / 8);
- b = Convert.ToByte(Bits % 8);
- int length = StrIn.Length;
- text2 = StrIn;
- if (length * 8 > Bits)
- {
- if (num > 0)
- {
- text2 = text2.Substring(length, (int)(length - num));
- for (int i = 0; i < num; i++)
- {
- text2 += '\0';
- }
- }
- byte b2 = 0;
- string text3 = "";
- for (int i = length - 1; i >= 0; i--)
- {
- byte b3 = (byte)text2[i];
- byte b4 = (byte)((int)b3 / (int)(byte)Math.Pow(2.0, (double)(8 - b)));
- byte b5 = (byte)((int)b3 % (int)(byte)Math.Pow(2.0, (double)(8 - b)));
- b3 = (byte)((double)(int)b5 * Math.Pow(2.0, (double)(int)b));
- b3 = Convert.ToByte(b3 | b2);
- text3 += (char)b3;
- b2 = b4;
- }
- text = "";
- for (int i = length - 1; i >= 0; i--)
- {
- text += text3[i];
- }
- }
- else
- {
- for (int i = 0; i < length; i++)
- {
- text += '\0';
- }
- }
- return text;
- }
- public static string ShiftStrLeft(string StrIn, long Bits)
- {
- int num = 0;
- string text = null;
- string text2 = null;
- byte b = 0;
- byte b2 = 0;
- byte b3 = 0;
- byte b4 = 0;
- long num2 = 0L;
- byte b5 = 0;
- byte b6 = 0;
- byte b7 = 0;
- byte b8 = 0;
- num2 = Convert.ToInt64(Bits / 8);
- b4 = Convert.ToByte(Bits % 8);
- b2 = Convert.ToByte(255.0 - (Math.Pow(2.0, (double)(8 - b4)) - 1.0));
- b3 = (byte)(~b2);
- b8 = Convert.ToByte(Math.Pow(2.0, (double)(int)b4) - 1.0);
- num = 0;
- int length = StrIn.Length;
- int num3 = length * 8;
- text = StrIn;
- if (num3 > Bits)
- {
- if (num2 > 0)
- {
- text = text.Substring(length, (int)(length - num2));
- for (num = 0; num < num2; num++)
- {
- text += '\0';
- }
- text2 = text;
- }
- if (b4 > 0)
- {
- for (num = 0; num < text.Length; num++)
- {
- byte[] bytes = Encoding.ASCII.GetBytes(text.Substring(num, 1));
- b = bytes[0];
- b5 = Convert.ToByte(b & b2 & 0xFF);
- b6 = Convert.ToByte(b & b3 & 0xFF);
- b5 = (byte)((double)(int)b5 / Math.Pow(2.0, (double)(8 - b4)));
- b6 = (byte)((double)(int)b6 * Math.Pow(2.0, (double)(int)b4));
- if (num == 0)
- {
- b7 = b6;
- text2 = "";
- }
- else
- {
- b7 = (byte)(b7 | b5);
- text2 += (char)b7;
- b7 = b6;
- }
- }
- b7 = (byte)(b7 | (b5 & ~b8));
- text2 += (char)b7;
- }
- }
- else
- {
- for (num = 0; num < length; num++)
- {
- text2 += '\0';
- }
- }
- return text2;
- }
- public static string MyShiftToRight(string StrIn, long Bits)
- {
- string text = "";
- byte b = 0;
- long num = 0L;
- string text2 = null;
- num = Convert.ToInt64(Bits / 8);
- b = Convert.ToByte(Bits % 8);
- int length = StrIn.Length;
- text2 = StrIn;
- if (length * 8 > Bits)
- {
- if (num > 0)
- {
- text2 = text2.Substring(length, (int)(length - num));
- for (int i = 0; i < num; i++)
- {
- text2 += '\0';
- }
- }
- byte b2 = 0;
- string text3 = "";
- for (int i = 0; i < length; i++)
- {
- byte b3 = (byte)text2[i];
- byte b4 = (byte)((int)b3 / (int)(byte)Math.Pow(2.0, (double)(int)b));
- byte b5 = (byte)((int)b3 % (int)(byte)Math.Pow(2.0, (double)(int)b));
- b3 = b4;
- b3 = Convert.ToByte(b3 | b2 * (byte)Math.Pow(2.0, (double)(8 - b)));
- text3 += (char)b3;
- b2 = b5;
- }
- text = "";
- for (int i = 0; i < length; i++)
- {
- text += text3[i];
- }
- }
- else
- {
- for (int i = 0; i < length; i++)
- {
- text += '\0';
- }
- }
- return text;
- }
- public static char[] HexStrToBinStr(string StrIn)
- {
- char[] array = new char[StrIn.Length / 2];
- for (int i = 0; i < StrIn.Length - 1; i += 2)
- {
- string value = StrIn.Substring(i, 2);
- byte b = Convert.ToByte(value, 16);
- char c = (char)b;
- array[i / 2] = (char)b;
- }
- return array;
- }
- private static string DigestStrToHexStr(string SourceString)
- {
- MD5Init();
- byte[] inputBuffer = StringToArray(SourceString);
- MD5Update(SourceString.Length, inputBuffer);
- MD5Final();
- return GetValues();
- }
- private static byte[] StringToArray(string InString)
- {
- byte[] array = new byte[InString.Length + 1];
- for (int i = 0; i <= InString.Length; i++)
- {
- if (i == InString.Length)
- {
- array[i] = 0;
- }
- else
- {
- array[i] = (byte)InString[i];
- }
- }
- return array;
- }
- private static string GetValues()
- {
- return LongToString(State[0]) + LongToString(State[1]) + LongToString(State[2]) + LongToString(State[3]);
- }
- private static string LongToString(long Num)
- {
- string text = "";
- byte[] array = new byte[1];
- byte[] array2 = new byte[1];
- byte[] array3 = new byte[1];
- byte[] array4 = new byte[1];
- array[0] = (byte)(Num & 0xFF);
- array2[0] = (byte)((Num & 0xFF00) / 256);
- array3[0] = (byte)((Num & 0xFF0000) / 65536);
- text = BitConverter.ToString(array).Replace("-", "");
- text += BitConverter.ToString(array2).Replace("-", "");
- text += BitConverter.ToString(array3).Replace("-", "");
- if (Num < 0)
- {
- array4[0] = (byte)((Num & 0x7F000000) / 16777216 | 0x80);
- }
- else
- {
- array4[0] = (byte)((Num & 4278190080u) / 16777216);
- }
- return text + BitConverter.ToString(array4).Replace("-", "");
- }
- private static void MD5Final()
- {
- byte[] array = new byte[72]
- {
- 128,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0
- };
- long value = ByteCounter * 8;
- long num = ByteCounter % 64;
- if (num <= 56)
- {
- MD5Update(56 - num, array);
- }
- else
- {
- MD5Update(120 - ByteCounter, array);
- }
- array[0] = (byte)(UnsignedToLong(value) & 0xFF);
- array[1] = (byte)((int)(UnsignedToLong(value) / 256) & 0xFF);
- array[2] = (byte)((int)(UnsignedToLong(value) / 65536) & 0xFF);
- array[3] = (byte)((int)(UnsignedToLong(value) / 16777216) & 0xFF);
- array[4] = 0;
- array[5] = 0;
- array[6] = 0;
- array[7] = 0;
- MD5Update(8L, array);
- }
- private static void MD5Init()
- {
- ByteCounter = 0L;
- State[0] = UnsignedToLong(1732584193L);
- State[1] = UnsignedToLong(4023233417L);
- State[2] = UnsignedToLong(2562383102L);
- State[3] = UnsignedToLong(271733878L);
- }
- private static long UnsignedToLong(long value)
- {
- if (value < 0 || value >= 4294967296L)
- {
- return 6L;
- }
- if (value <= 2147483647)
- {
- return value;
- }
- return value - 4294967296L;
- }
- private static long LongToUnsigned(long value)
- {
- if (value < 0)
- {
- return value + 4294967296L;
- }
- return value;
- }
- private static void MD5Update(long InputLen, byte[] InputBuffer)
- {
- long num = ByteCounter % 64;
- long num2 = 64 - num;
- ByteCounter += InputLen;
- long num5;
- if (InputLen >= num2)
- {
- long num3;
- for (num3 = 0L; num3 < num2; num3++)
- {
- ByteBuffer[num + num3] = InputBuffer[num3];
- }
- MD5Transform(ByteBuffer);
- long num4 = InputLen % 64;
- for (num5 = num2; num5 <= InputLen - num3 - num4; num5 += 64)
- {
- for (long num6 = 0L; num6 < 64; num6++)
- {
- ByteBuffer[num6] = InputBuffer[num5 + num6];
- }
- MD5Transform(ByteBuffer);
- }
- num = 0L;
- }
- else
- {
- num5 = 0L;
- }
- for (long num7 = 0L; num7 < InputLen - num5; num7++)
- {
- ByteBuffer[num + num7] = InputBuffer[num5 + num7];
- }
- }
- private static void MD5Transform(byte[] Buffer)
- {
- long num = State[0];
- long num2 = State[1];
- long num3 = State[2];
- long num4 = State[3];
- long[] array = Decode(64, Buffer);
- FF(ref num, num2, num3, num4, array[0], 7L, -680876936L);
- FF(ref num4, num, num2, num3, array[1], 12L, -389564586L);
- FF(ref num3, num4, num, num2, array[2], 17L, 606105819L);
- FF(ref num2, num3, num4, num, array[3], 22L, -1044525330L);
- FF(ref num, num2, num3, num4, array[4], 7L, -176418897L);
- FF(ref num4, num, num2, num3, array[5], 12L, 1200080426L);
- FF(ref num3, num4, num, num2, array[6], 17L, -1473231341L);
- FF(ref num2, num3, num4, num, array[7], 22L, -45705983L);
- FF(ref num, num2, num3, num4, array[8], 7L, 1770035416L);
- FF(ref num4, num, num2, num3, array[9], 12L, -1958414417L);
- FF(ref num3, num4, num, num2, array[10], 17L, -42063L);
- FF(ref num2, num3, num4, num, array[11], 22L, -1990404162L);
- FF(ref num, num2, num3, num4, array[12], 7L, 1804603682L);
- FF(ref num4, num, num2, num3, array[13], 12L, -40341101L);
- FF(ref num3, num4, num, num2, array[14], 17L, -1502002290L);
- FF(ref num2, num3, num4, num, array[15], 22L, 1236535329L);
- GG(ref num, num2, num3, num4, array[1], 5L, -165796510L);
- GG(ref num4, num, num2, num3, array[6], 9L, -1069501632L);
- GG(ref num3, num4, num, num2, array[11], 14L, 643717713L);
- GG(ref num2, num3, num4, num, array[0], 20L, -373897302L);
- GG(ref num, num2, num3, num4, array[5], 5L, -701558691L);
- GG(ref num4, num, num2, num3, array[10], 9L, 38016083L);
- GG(ref num3, num4, num, num2, array[15], 14L, -660478335L);
- GG(ref num2, num3, num4, num, array[4], 20L, -405537848L);
- GG(ref num, num2, num3, num4, array[9], 5L, 568446438L);
- GG(ref num4, num, num2, num3, array[14], 9L, -1019803690L);
- GG(ref num3, num4, num, num2, array[3], 14L, -187363961L);
- GG(ref num2, num3, num4, num, array[8], 20L, 1163531501L);
- GG(ref num, num2, num3, num4, array[13], 5L, -1444681467L);
- GG(ref num4, num, num2, num3, array[2], 9L, -51403784L);
- GG(ref num3, num4, num, num2, array[7], 14L, 1735328473L);
- GG(ref num2, num3, num4, num, array[12], 20L, -1926607734L);
- HH(ref num, num2, num3, num4, array[5], 4L, -378558L);
- HH(ref num4, num, num2, num3, array[8], 11L, -2022574463L);
- HH(ref num3, num4, num, num2, array[11], 16L, 1839030562L);
- HH(ref num2, num3, num4, num, array[14], 23L, -35309556L);
- HH(ref num, num2, num3, num4, array[1], 4L, -1530992060L);
- HH(ref num4, num, num2, num3, array[4], 11L, 1272893353L);
- HH(ref num3, num4, num, num2, array[7], 16L, -155497632L);
- HH(ref num2, num3, num4, num, array[10], 23L, -1094730640L);
- HH(ref num, num2, num3, num4, array[13], 4L, 681279174L);
- HH(ref num4, num, num2, num3, array[0], 11L, -358537222L);
- HH(ref num3, num4, num, num2, array[3], 16L, -722521979L);
- HH(ref num2, num3, num4, num, array[6], 23L, 76029189L);
- HH(ref num, num2, num3, num4, array[9], 4L, -640364487L);
- HH(ref num4, num, num2, num3, array[12], 11L, -421815835L);
- HH(ref num3, num4, num, num2, array[15], 16L, 530742520L);
- HH(ref num2, num3, num4, num, array[2], 23L, -995338651L);
- II(ref num, num2, num3, num4, array[0], 6L, -198630844L);
- II(ref num4, num, num2, num3, array[7], 10L, 1126891415L);
- II(ref num3, num4, num, num2, array[14], 15L, -1416354905L);
- II(ref num2, num3, num4, num, array[5], 21L, -57434055L);
- II(ref num, num2, num3, num4, array[12], 6L, 1700485571L);
- II(ref num4, num, num2, num3, array[3], 10L, -1894986606L);
- II(ref num3, num4, num, num2, array[10], 15L, -1051523L);
- II(ref num2, num3, num4, num, array[1], 21L, -2054922799L);
- II(ref num, num2, num3, num4, array[8], 6L, 1873313359L);
- II(ref num4, num, num2, num3, array[15], 10L, -30611744L);
- II(ref num3, num4, num, num2, array[6], 15L, -1560198380L);
- II(ref num2, num3, num4, num, array[13], 21L, 1309151649L);
- II(ref num, num2, num3, num4, array[4], 6L, -145523070L);
- II(ref num4, num, num2, num3, array[11], 10L, -1120210379L);
- II(ref num3, num4, num, num2, array[2], 15L, 718787259L);
- II(ref num2, num3, num4, num, array[9], 21L, -343485551L);
- State[0] = LongOverflowAdd(State[0], num);
- State[1] = LongOverflowAdd(State[1], num2);
- State[2] = LongOverflowAdd(State[2], num3);
- State[3] = LongOverflowAdd(State[3], num4);
- }
- private static void FF(ref long A, long B, long C, long D, long X, long S, long ac)
- {
- A = LongOverflowAdd4(A, (B & C) | (~B & D), X, ac);
- A = LongLeftRotate(A, S);
- A = LongOverflowAdd(A, B);
- }
- private static void GG(ref long A, long B, long C, long D, long X, long S, long ac)
- {
- A = LongOverflowAdd4(A, (B & D) | (C & ~D), X, ac);
- A = LongLeftRotate(A, S);
- A = LongOverflowAdd(A, B);
- }
- private static void HH(ref long A, long B, long C, long D, long X, long S, long ac)
- {
- A = LongOverflowAdd4(A, B ^ C ^ D, X, ac);
- A = LongLeftRotate(A, S);
- A = LongOverflowAdd(A, B);
- }
- private static void II(ref long A, long B, long C, long D, long X, long S, long ac)
- {
- A = LongOverflowAdd4(A, C ^ (B | ~D), X, ac);
- A = LongLeftRotate(A, S);
- A = LongOverflowAdd(A, B);
- }
- private static long LongLeftRotate(long value, long Bits)
- {
- Bits %= 32;
- if (Bits == 0)
- {
- return value;
- }
- long num = 0L;
- for (long num2 = 1L; num2 <= Bits; num2++)
- {
- long num3 = value & -1073741824;
- value = (value & 0x3FFFFFFF) * 2;
- num = value;
- int num4 = (num3 < 0) ? 1 : 0;
- if (num3 < 0 && num3 != -1073741824)
- {
- value += num4;
- }
- if (num3 == 1073741824)
- {
- value += -2147483648;
- }
- if (num3 == -1073741824)
- {
- value = value + -2147483648 + 1;
- }
- }
- return value;
- }
- private static long LongOverflowAdd(long Val1, long Val2)
- {
- long num = (Val1 & 0xFFFF) + (Val2 & 0xFFFF);
- long num2 = num / 65536;
- long num3 = (Val1 & 4294901760u) / 65536 + (Val2 & 4294901760u) / 65536 + num2 & 0xFFFF;
- return UnsignedToLong(num3 * 65536 + (num & 0xFFFF));
- }
- private static long LongOverflowAdd4(long Val1, long Val2, long val3, long val4)
- {
- long num = (Val1 & 0xFFFF) + (Val2 & 0xFFFF) + (val3 & 0xFFFF) + (val4 & 0xFFFF);
- long num2 = num / 65536;
- long num3 = (Val1 & 4294901760u) / 65536 + (Val2 & 4294901760u) / 65536 + (val3 & 4294901760u) / 65536 + (val4 & 4294901760u) / 65536 + num2 & 0xFFFF;
- return UnsignedToLong(num3 * 65536 + (num & 0xFFFF));
- }
- private static long[] Decode(int Length, byte[] InputBuffer)
- {
- long[] array = new long[Length / 4];
- int num = 0;
- for (int i = 0; i < Length; i += 4)
- {
- double num2 = (double)(InputBuffer[i] + InputBuffer[i + 1] * 256 + InputBuffer[i + 2] * 65536 + InputBuffer[i + 3] * 16777216);
- array[num] = (long)num2;
- num++;
- }
- return array;
- }
- public static string FormatKeyCode(string StrIn, int GrpLen)
- {
- int num = 0;
- int num2 = 0;
- string text = null;
- string text2 = null;
- int num3 = 0;
- int num4 = 0;
- num = StrIn.Length;
- int num5 = num / GrpLen;
- num4 = num % GrpLen;
- for (num2 = 0; num2 < num5; num2++)
- {
- num3 = num2 * GrpLen;
- text2 = StrIn.Substring(num3, GrpLen);
- text = ((num2 <= 0) ? (text + text2) : (text + "-" + text2));
- }
- if (num4 > 0)
- {
- text = text + "-" + StrIn.Substring(StrIn.Length - num4, num4);
- }
- return text;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement