Example #1
0
        private BitArray F(BitArray bitArray, BitArray key)
        {
            if (bitArray.Count != 4)
            {
                throw new ArgumentException("F argument length should be 4 bits");
            }

            var permuteAndExpand = new BitArray(8)
            {
                [0] = bitArray[3],
                [1] = bitArray[0],
                [2] = bitArray[1],
                [3] = bitArray[2],
                [4] = bitArray[1],
                [5] = bitArray[2],
                [6] = bitArray[3],
                [7] = bitArray[0]
            };
            var xoredWithKey = permuteAndExpand.NormalXor(key);

            var leftPart  = SimplifiedDesHelper.GetLeftPart(xoredWithKey);
            var rightPart = SimplifiedDesHelper.GetRightPart(xoredWithKey);

            var leftPartSboxed  = Sbox(leftPart, 1);
            var rightPartSboxed = Sbox(rightPart, 2);

            return(SimplifiedDesHelper.P4(leftPartSboxed.Merge(rightPartSboxed)));
        }
Example #2
0
        private BitArray Switch(BitArray bitArray)
        {
            var leftPart  = SimplifiedDesHelper.GetLeftPart(bitArray);
            var rightPart = SimplifiedDesHelper.GetRightPart(bitArray);

            return(rightPart.Merge(leftPart));
        }
Example #3
0
        private BitArray Fk(BitArray afterIp, BitArray key)
        {
            var left  = SimplifiedDesHelper.GetLeftPart(afterIp);
            var right = SimplifiedDesHelper.GetRightPart(afterIp);

            left = left.NormalXor(F(right, key));
            return(left.Merge(right));
        }