예제 #1
0
        private static IEnumerable <RoundWords> ChunkTogetherRoundKeys(IEnumerable <byte[]> allKeys)
        {
            IList <RoundWords> roundWords = new List <RoundWords>();

            for (int i = 0; i < allKeys.Count() / 4; i++)
            {
                RoundWords           wordWrap       = new RoundWords();
                IEnumerable <byte[]> wordsAfterSkip = allKeys.Skip(i * 4);
                IEnumerable <byte[]> words          = wordsAfterSkip.Take(4);
                wordWrap.Words = words;
                roundWords.Add(wordWrap);
            }

            return(roundWords);
        }
예제 #2
0
        public ByteArray AddRoundKey(ByteArray state, RoundWords roundKeys4)
        {
            if (roundKeys4.Words.Count() != 4)
            {
                throw new ArgumentOutOfRangeException("roundKeys4", "Round key must have 4 words");
            }

            ByteArray copyState = new ByteArray(state.Length);

            for (int i = 0; i < state.Length; i++)
            {
                for (int j = 0; j < state.Length; j++)
                {
                    byte[] word      = roundKeys4.Words.ElementAt(j);
                    byte   stateByte = state[i, j];
                    byte   wordByte  = word[i];
                    copyState[i, j] = (byte)(stateByte ^ wordByte);
                }
            }

            return(copyState);
        }
예제 #3
0
 public void UpdateState(Func <ByteArray, RoundWords, ByteArray> addRoundKeyMethod, int roundNumber, string actionName, RoundWords roundWords)
 {
     State          = addRoundKeyMethod(State, roundWords);
     RoundNumber    = roundNumber;
     LastActionName = actionName;
     OnStateChange(new AesStateChangeEventArgs(State, RoundNumber, LastActionName));
 }