Пример #1
0
        public void createMessage()
        {
            string message = "0123456789ABCDEF";

            BitArray excepted_message;
            string given_message_table = "00000001 00100011 01000101 01100111 10001001 10101011 11001101 11101111";
            // message
            excepted_message = this.fromStringToBitArray(given_message_table, 64);
            Message test_message = new Message(message, 0);

            CollectionAssert.AreEqual(excepted_message, test_message.bitMsg, "Excepted:\n" + this.bitArrayToString(excepted_message) + " Actual\n" + this.bitArrayToString(test_message.bitMsg));
        }
Пример #2
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));
        }
Пример #3
0
        public void splittingMessage()
        {
            string message = "0123456789ABCDEF";

            BitArray excepted_left_message;
            BitArray excepted_right_message;
            string message_left_side = "11001100 00000000 11001100 11111111";
            string message_right_side = "11110000 10101010 11110000 10101010";

            excepted_left_message = this.fromStringToBitArray(message_left_side, 32);
            excepted_right_message = this.fromStringToBitArray(message_right_side, 32);

            Message test_message = new Message(message, 0);
            test_message.initialPermutation();
            test_message.splitting();
            CollectionAssert.AreEqual(excepted_left_message, test_message.msg_left_side, "Excepted:\n" + this.bitArrayToString(excepted_left_message) + " Actual\n" + this.bitArrayToString(test_message.msg_left_side));
            CollectionAssert.AreEqual(excepted_right_message, test_message.msg_right_side, "Excepted:\n" + this.bitArrayToString(excepted_right_message) + " Actual\n" + this.bitArrayToString(test_message.msg_right_side));
        }
Пример #4
0
 public void loadMsg()
 {
     string path = "test.bin";
     Message msg = new Message(path);
     CollectionAssert.AllItemsAreNotNull(msg.bitMsg);
 }
Пример #5
0
        public void initialPermutation()
        {
            Message msg = new Message("testowanie.bin");
            msg.initialPermutation();
            Message expected = new Message("expected.bin");

            CollectionAssert.AreEqual(expected.bitMsg, msg.bitMsg, "expected:" + expected.bitMsg.ToString() + "result:" + msg.bitMsg.ToString());
        }
Пример #6
0
        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;
        }