Esempio n. 1
0
        private void EncryptTransform(byte[] data)
        {
            int size = data.Length;

            int  j;
            byte a, c;

            for (int i = 0; i < 3; i++)
            {
                a = 0;
                for (j = size; j > 0; j--)
                {
                    c  = data[size - j];
                    c  = RollLeft(c, 3);
                    c  = (byte)(c + j);
                    c ^= a;
                    a  = c;
                    c  = RollRight(a, j);
                    c ^= 0xFF;
                    c += 0x48;
                    data[size - j] = c;
                }
                a = 0;
                for (j = data.Length; j > 0; j--)
                {
                    c           = data[j - 1];
                    c           = RollLeft(c, 4);
                    c           = (byte)(c + j);
                    c          ^= a;
                    a           = c;
                    c          ^= 0x13;
                    c           = RollRight(c, 3);
                    data[j - 1] = c;
                }
            }

            m_aesCipher.Transform(data, m_IV);
        }
Esempio n. 2
0
        public unsafe void Transform(byte[] data)
        {
            m_aesCipher.Transform(data, m_IV);

            byte[] newIV = new byte[IVLength] {
                0xF2, 0x53, 0x50, 0xC6
            };

            for (int i = 0; i < IVLength; i++)
            {
                byte input      = m_IV[i];
                byte tableInput = sShiftKey[input];

                newIV[0] += (byte)(sShiftKey[newIV[1]] - input);
                newIV[1] -= (byte)(newIV[2] ^ tableInput);
                newIV[2] ^= (byte)(sShiftKey[newIV[3]] + input);
                newIV[3] -= (byte)(newIV[0] - tableInput);

                fixed(byte *ptr = newIV)
                * (uint *)ptr = (*(uint *)ptr << 3) | (*(uint *)ptr >> 32 - 3); //RC6 ROL 3
            }

            Buffer.BlockCopy(newIV, 0, m_IV, 0, IVLength);
        }