예제 #1
0
        public ulong[] Encrypt(ulong[] plainText, ulong[] chipherKey)
        {
            int round = 0;

            ulong[] state = new ulong[Nb];

            ulong[][] roundKeys = KalynaTransformation.KeyExpansion(chipherKey, ref state, Nb, Nk, Nr);

            Array.Copy(plainText, state, Nb);

            KalynaTransformation.AddRoundKey(roundKeys[round], state);
            for (round = 1; round < Nr; ++round)
            {
                KalynaTransformation.EncipherRound(ref state);
                KalynaTransformation.XorRoundKey(roundKeys[round], state);
            }
            KalynaTransformation.EncipherRound(ref state);
            KalynaTransformation.AddRoundKey(roundKeys[Nr], state);

            return(state);
        }
예제 #2
0
        public ulong[] Decrypt(ulong[] chipherText, ulong[] chipherKey)
        {
            uint round = Nr;

            ulong[] state = new ulong[Nb];

            ulong[][] roundKeys = KalynaTransformation.KeyExpansion(chipherKey, ref state, Nb, Nk, Nr);

            Array.Copy(chipherText, state, Nb);

            KalynaTransformation.SubRoundKey(roundKeys[round], state);
            for (round = Nr - 1; round > 0; --round)
            {
                KalynaTransformation.DecipherRound(ref state);
                KalynaTransformation.XorRoundKey(roundKeys[round], state);
            }
            KalynaTransformation.DecipherRound(ref state);
            KalynaTransformation.SubRoundKey(roundKeys[0], state);

            return(state);
        }