Beispiel #1
0
        public static string GET_GTK(string skey)
        {
            var arg  = "tencentQQVIP123443safde&!%^%1282";
            var list = new List <int>();
            var num  = 5381;

            list.Add(172192);
            var i = 0;

            for (var length = skey.Length; i < length; i++)
            {
                int num2 = Encoding.UTF8.GetBytes(skey)[i];
                list.Add((num << 5) + num2);
                num = num2;
            }

            var stringBuilder = new StringBuilder();

            for (i = 0; i < list.Count; i++)
            {
                stringBuilder.Append(list[i].ToString());
            }

            return(QQTea.Md5(stringBuilder + arg));
        }
Beispiel #2
0
        private static void code(byte[] In, int inOffset, int inPos, byte[] Out, int outOffset, int outPos, byte[] key)
        {
            if (outPos > 0)
            {
                for (int i = 0; i < 8; i++)
                {
                    In[outOffset + outPos + i] = System.BitConverter.GetBytes(In[inOffset + inPos + i] ^ Out[outOffset + outPos + i - 8])[0];
                }
            }
            uint[] array = QQTea.FormatKey(key);
            uint   num   = QQTea.ConvertByteArrayToUInt(In, outOffset + outPos);
            uint   num2  = QQTea.ConvertByteArrayToUInt(In, outOffset + outPos + 4);
            uint   num3  = 0u;
            uint   num4  = 2654435769u;
            uint   num5  = 16u;

            while (num5-- > 0u)
            {
                num3 += num4;
                num  += ((num2 << 4) + array[0] ^ num2 + num3 ^ (num2 >> 5) + array[1]);
                num2 += ((num << 4) + array[2] ^ num + num3 ^ (num >> 5) + array[3]);
            }
            Array.Copy(QQTea.ConvertUIntToByteArray(num), 0, Out, outOffset + outPos, 4);
            Array.Copy(QQTea.ConvertUIntToByteArray(num2), 0, Out, outOffset + outPos + 4, 4);
            if (inPos > 0)
            {
                for (int j = 0; j < 8; j++)
                {
                    Out[outOffset + outPos + j] = System.BitConverter.GetBytes(Out[outOffset + outPos + j] ^ In[inOffset + inPos + j - 8])[0];
                }
            }
        }
Beispiel #3
0
        private static uint[] FormatKey(byte[] key)
        {
            if (key.Length == 0)
            {
                throw new ArgumentException("Key must be between 1 and 16 characters in length");
            }
            byte[] array = new byte[16];
            if (key.Length < 16)
            {
                Array.Copy(key, 0, array, 0, key.Length);
                for (int i = key.Length; i < 16; i++)
                {
                    array[i] = 32;
                }
            }
            else
            {
                Array.Copy(key, 0, array, 0, 16);
            }
            uint[] array2 = new uint[4];
            int    num    = 0;

            for (int j = 0; j < array.Length; j += 4)
            {
                array2[num++] = QQTea.ConvertByteArrayToUInt(array, j);
            }
            return(array2);
        }
Beispiel #4
0
        public static byte[] Encrypt(byte[] In, int offset, int len, byte[] key)
        {
            Random random = new Random();
            int    num    = (len + 10) % 8;

            if (num != 0)
            {
                num = 8 - num;
            }
            byte[] array = new byte[len + num + 10];
            array[0] = (byte)((random.Next() & 248) | num);
            for (int i = 1; i < num + 3; i++)
            {
                array[i] = (byte)(random.Next() & 255);
            }
            Array.Copy(In, 0, array, num + 3, len);
            for (int j = num + 3 + len; j < array.Length; j++)
            {
                array[j] = 0;
            }
            byte[] array2 = new byte[len + num + 10];
            for (int k = 0; k < array2.Length; k += 8)
            {
                QQTea.code(array, 0, k, array2, 0, k, key);
            }
            return(array2);
        }
Beispiel #5
0
        public static byte[] Decrypt(byte[] In, int offset, int len, byte[] key)
        {
            var temp = new byte[In.Length];

            Buffer.BlockCopy(In, 0, temp, 0, In.Length);
            if (len % 8 != 0 || len < 16)
            {
                return(null);
            }
            byte[] array = new byte[len];
            for (int i = 0; i < len; i += 8)
            {
                QQTea.decode(temp, offset, i, array, 0, i, key);
            }
            for (int j = 8; j < len; j++)
            {
                array[j] ^= temp[offset + j - 8];
            }
            int num = (int)(array[0] & 7);

            len = len - num - 10;
            byte[] array2 = new byte[len];
            Array.Copy(array, num + 3, array2, 0, len);
            return(array2);
        }
Beispiel #6
0
        public static byte[] Decrypt(byte[] In, int offset, int len, byte[] key)
        {
            if (len % 8 != 0 || len < 16)
            {
                return(null);
            }
            byte[] array = new byte[len];
            for (int i = 0; i < len; i += 8)
            {
                QQTea.decode(In, offset, i, array, 0, i, key);
            }
            for (int j = 8; j < len; j++)
            {
                array[j] ^= In[offset + j - 8];
            }
            int num = (int)(array[0] & 7);

            len = len - num - 10;
            byte[] array2 = new byte[len];
            Array.Copy(array, num + 3, array2, 0, len);
            return(array2);
        }