public void TestShiftRows()
        {
            string s = "12345689abcdefgh";
            byte[] expectedStateData = { 0x31, 0x36, 0x63, 0x68,
                                         0x35, 0x62, 0x67, 0x34,
                                         0x61, 0x66, 0x33, 0x39,
                                         0x65, 0x32, 0x38, 0x64  };
            State expectedState = new State(expectedStateData);
            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            State start = new State(inputPlain);

            start = start.shiftRows();

            Console.Out.WriteLine("shift:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestMixColumns()
        {
            string s = "12345689abcdefgh";
            byte[] expectedStateData = { 0x33, 0x34, 0x39, 0x3a,
                                         0x31, 0x28, 0x38, 0x23,
                                         0x63, 0x64, 0x69, 0x6a,
                                         0x6f, 0x68, 0x75, 0x7e  };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            State start = new State(inputPlain);

            start = start.mixColumns();

            Console.Out.WriteLine("mix:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestSubBytes()
        {
            // test vector: according to Casper Schellekens
            string s = "12345689abcdefgh";
            byte[] expectedStateData = { 0xc7, 0x23, 0xc3, 0x18,
                                     0x96, 0x05, 0x07, 0x12,
                                     0xef, 0xaa, 0xfb, 0x43,
                                     0x4d, 0x33, 0x85, 0x45 };
            State expectedState = new State(expectedStateData);
            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            State start = new State(inputPlain);

            start = start.subBytes();

            Console.Out.WriteLine("subBytes:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestAddRoundKey0()
        {
            string s = "12345689abcdefgh";
            byte[] inputKey = { 0x11, 0x22, 0x33, 0x44,
                                0x55, 0x66, 0x77, 0x88,
                                0x99, 0x00, 0xaa, 0xbb,
                                0xcc, 0xdd, 0xee, 0xff };
            byte[] expectedStateData = { 32, 16, 0, 112, 96, 80, 79, 177, 248, 98, 201, 223, 169, 187, 137, 151 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            Key key = new Key(inputKey);
            State start = new State(inputPlain);

            start = start.addRoundKey(key, 0);

            Console.Out.WriteLine("add0:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestMixColumnsInv()
        {
            string s = "12345689abcdefgh";
            byte[] expectedStateData = { 0x1b, 0x0c, 0x11, 0x02,
                                         0x15, 0x04, 0x1c, 0x0f,
                                         0x4b, 0x5c, 0x41, 0x52,
                                         0x07, 0x30, 0x1d, 0x26 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            State start = new State(inputPlain);

            start = start.mixColumnsInv();

            Console.Out.WriteLine("mix:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestSubBytesInv()
        {
            string s = "12345689abcdefgh";
            byte[] expectedStateData = { 0x2e, 0xa1, 0x66, 0x28,
                                     0xd9, 0x24, 0x76, 0x5b,
                                     0xd8, 0xab, 0x00, 0x8c,
                                     0xbc, 0xd3, 0x0a, 0xf7 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            State start = new State(inputPlain);

            start = start.subBytesInv();

            Console.Out.WriteLine("subBytes:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestShiftRowsInv()
        {
            string s = "12345689abcdefgh";
            byte[] expectedStateData = { 0x31, 0x66, 0x63, 0x39,
                                         0x35,0x32,0x67,0x64,
                                         0x61,0x36,0x33,0x68,
                                         0x65,0x62,0x38,0x34 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            State start = new State(inputPlain);
            start = start.shiftRowsInv();
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
        public void TestAddRoundKey7()
        {
            string s = "12345689abcdefgh";
            byte[] inputKey = { 0x11, 0x22, 0x33, 0x44,
                                0x55, 0x66, 0x77, 0x88,
                                0x99, 0x00, 0xaa, 0xbb,
                                0xcc, 0xdd, 0xee, 0xff };
            byte[] expectedStateData = { 42, 45, 180, 25, 155, 188, 117, 243, 155, 228, 10, 60, 124, 122, 249, 208 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            Key key = new Key(inputKey);
            State start = new State(inputPlain);
            start = start.addRoundKey(key, 7);
            Console.Out.WriteLine("add7:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }