Beispiel #1
0
        private int Transform(int data, int firstSubkeyIdx, int secondSubkeyIdx)
        {
            int block = CombinatoricsUtil.Permutate(data, IP);

            block = fK(block, subkeys[firstSubkeyIdx]);
            block = SW(block);
            block = fK(block, subkeys[secondSubkeyIdx]);
            return(CombinatoricsUtil.Permutate(block, IIP));
        }
Beispiel #2
0
        private int F(int block, int subkey)
        {
            int extended = CombinatoricsUtil.Permutate(block, E) ^ subkey;

            int[] parts = CombinatoricsUtil.Halve(extended, HALF_OF_BLOCK);
            int   left  = S_BOXES[0][FindSBoxIndex(parts[0])];
            int   right = S_BOXES[1][FindSBoxIndex(parts[1])];

            return(CombinatoricsUtil.Permutate((left << 2) | right, P4));
        }
Beispiel #3
0
        public void CheckSinglePermutate()
        {
            int expectedPermutatedResult = 290;
            int input = 100;

            int[] permutation = { 2, 4, 1, 6, 3, 9, 0, 8, 7, 5 };
            int   result      = CombinatoricsUtil.Permutate(input, permutation);

            Assert.AreEqual(expectedPermutatedResult, result);
        }
Beispiel #4
0
        private int[] KeySchedule(int key)
        {
            int permutatedKey = CombinatoricsUtil.Permutate(key, P10);

            int[] parts = CombinatoricsUtil.Halve(permutatedKey, HALF_OF_KEY);
            int   left  = parts[0];
            int   right = parts[1];

            subkeys = new int[2];

            for (int i = 0; i < 2; i++)
            {
                left       = CombinatoricsUtil.CyclicShiftToLeft(left, i + 1, HALF_OF_KEY);
                right      = CombinatoricsUtil.CyclicShiftToLeft(right, i + 1, HALF_OF_KEY);
                subkeys[i] = CombinatoricsUtil.Permutate((left << HALF_OF_KEY) | right, P8);
            }

            return(subkeys);
        }