Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string message = "The brown fox is jumping over the lazy dog.";

            byte[] input = Encoding.ASCII.GetBytes(message);

            //byte[] encrypted = FeistelCipher.Process(Xor, keys, input, 3);

            //byte[] decrypted = FeistelCipher.Process(
            //    Xor, keys.Reverse().ToArray(), encrypted, 3);

            byte[] encrypted = FeistelCipher.Process <object>(MD5, null, input, 3);

            byte[] decrypted = FeistelCipher.Process <object>(MD5, null, encrypted, 3);

            byte[] result = new byte[input.Length];

            Array.Copy(decrypted, result, result.Length);

            string foo = Encoding.ASCII.GetString(result);

            Console.WriteLine(foo);

            Console.ReadKey();
        }
Exemplo n.º 2
0
        // The plain text will be padded to fill the size of block (16 bytes), so the encoded message should be aligned with the rule
        // (text.Length % 16 == 0)
        public static void TestEncodedMessageSize(string testCase, uint key)
        {
            // Arrange
            var encoder = new FeistelCipher();

            // Assert
            Assert.Throws <ArgumentException>(() => encoder.Decode(testCase, key));
        }
Exemplo n.º 3
0
        public static void DecodedStringIsTheSame([Random(100)] uint key)
        {
            // Arrange
            var encoder = new FeistelCipher();
            var random  = new Randomizer();

            int lenOfString = random.Next(1000);

            string message = random.GetString(lenOfString);

            // Act
            var encoded = encoder.Encode(message, key);
            var decoded = encoder.Decode(encoded, key);

            // Assert
            Assert.AreEqual(message, decoded);
        }