Example #1
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));
        }
Example #2
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);
        }
Example #3
0
 private int fK(int block, int subkey)
 {
     int[] parts = CombinatoricsUtil.Halve(block, HALF_OF_BLOCK);
     return((parts[0] ^ F(parts[1], subkey)) << HALF_OF_BLOCK | parts[1]);
 }