Ejemplo n.º 1
0
        public void decryptMessage()
        {
            string message = "0123456789ABCDEF";

            BitArray excepted_message;
            string excepted_message_string = "00000001 00100011 01000101 01100111 10001001 10101011 11001101 11101111";

            excepted_message = this.fromStringToBitArray(excepted_message_string);

            Key key = new Key("133457799BBCDFF1");
            key.initialPermutation();
            key.splitting();
            key.shifts();
            key.finalPermutation();

            Message test_message = new Message(message, 0);
            test_message.initialPermutation();
            test_message.splitting();

            Iteration.setKeys(key.keys);
            Iteration iteration = new Iteration(test_message.msg_left_side, test_message.msg_right_side);
            for (int i = 1; i <= 16; i++)
            {
                iteration.ePermutation(i);
                iteration.xorWithKey(i);
                iteration.sBoxing(i);
                iteration.pPermutation(i);
                iteration.afterIteration(i);
            }
            test_message.reverseConnecting(iteration.leftSide[16], iteration.rightSide[16]);
            test_message.finalPermutation();

            test_message = new Message(test_message.bitMsg);
            test_message.initialPermutation();
            test_message.splitting();
            key.reverseKey();
            Iteration.setKeys(key.keys);
            iteration = new Iteration(test_message.msg_left_side, test_message.msg_right_side);
            for (int i = 1; i <= 16; i++)
            {
                iteration.ePermutation(i);
                iteration.xorWithKey(i);
                iteration.sBoxing(i);
                iteration.pPermutation(i);
                iteration.afterIteration(i);
            }
            test_message.reverseConnecting(iteration.leftSide[16], iteration.rightSide[16]);
            test_message.finalPermutation();

            CollectionAssert.AreEqual(excepted_message, test_message.bitMsg, "Excepted:\n" + this.bitArrayToString(excepted_message) + " Actual\n" + this.bitArrayToString(test_message.bitMsg));
        }
Ejemplo n.º 2
0
Archivo: Utils.cs Proyecto: WPiotr/BSK
 public static void oneIteration(Iteration iteration, int counter)
 {
     iteration.ePermutation(counter);
     iteration.xorWithKey(counter);
     iteration.sBoxing(counter);
     iteration.pPermutation(counter);
     iteration.afterIteration(counter);
 }
Ejemplo n.º 3
0
        public void iterationTestInitialize()
        {
            this.iteration_test = new Iteration(left_side_test, right_side_test);

            Debug.WriteLine("Name: " + context.TestName);
        }
Ejemplo n.º 4
0
Archivo: Utils.cs Proyecto: WPiotr/BSK
        public static BitArray makeMessage(byte[] bit_message)
        {
            Message message = new Message(bit_message);
            message.initialPermutation();
            message.splitting();

            Iteration iteration = new Iteration(message.msg_left_side, message.msg_right_side);
            Iteration.setKeys(Utils.key.keys);
            for (int i = 1; i <= 16; i++)
            {
                Utils.oneIteration(iteration, i);
            }
            message.reverseConnecting(iteration.leftSide[16], iteration.rightSide[16]);
            message.finalPermutation();
            return message.bitMsg;
        }