예제 #1
0
        public void TestBlockify()
        {
            var message = "YELLOW SUBMARINE";

            Console.WriteLine("input: {0}", message);

            var input = Basic.AsciiToBytes(message);

            var blocked = Basic.Aes.Util.Blockify(input, 4, input.Length / 4);

            for (var i = 0; i < blocked.GetLength(0); i++)
            {
                for (var j = 0; j < blocked.GetLength(1); j++)
                {
                    Console.Write((char)blocked[i, j] + " ");
                }
                Console.Write('\n');
            }

            var unblocked = Basic.Aes.Util.Unblockify(blocked);

            var output = Basic.BytesToAscii(unblocked);

            Console.WriteLine("output: {0}", output);

            Assert.AreEqual(message, output);
        }
예제 #2
0
        public void EncipherText()
        {
            var message = Basic.AsciiToBytes(Basic.GetFileText(@"..\..\Assets\TestIsEnglishDistributed.txt"));
            var key     = Basic.AsciiToBytes("ICE");
            var cipher  = Basic.XorRepeatKey(message, key);

            Console.WriteLine(Basic.BytesToHex(cipher));
        }
예제 #3
0
        public void TestS2C9()
        {
            const string message = "YELLOW SUBMARINE";
            const string answer  = "59454c4c4f57205355424d4152494e4504040404";

            var paddedMessage = Basic.BytesToHex(BlockAndStream.Pad(Basic.AsciiToBytes(message), 20));

            Console.WriteLine(paddedMessage);
            Console.WriteLine(answer);
            Assert.AreEqual(answer, paddedMessage);
        }
예제 #4
0
        public void TestGetHammingDistance()
        {
            const string input1          = "this is a test";
            const string input2          = "wokka wokka!!!";
            const int    hammingDistance = 37;

            var input1Bytes = Basic.AsciiToBytes(input1);
            var input2Bytes = Basic.AsciiToBytes(input2);

            var result = Basic.GetHammingDistance(input1Bytes, input2Bytes);

            Assert.AreEqual(hammingDistance, result);
        }
예제 #5
0
        public void TestS1C5()
        {
            const string message = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal";
            const string target  = "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f";
            const string key     = "ICE";

            var messageBytes  = Basic.AsciiToBytes(message);
            var keyBytes      = Basic.AsciiToBytes(key);
            var eMessageBytes = Basic.XorRepeatKey(messageBytes, keyBytes);
            var eMessage      = Basic.BytesToHex(eMessageBytes);

            Assert.AreEqual(target, eMessage);
        }
예제 #6
0
        public void TestS1C7()
        {
            const string key  = "YELLOW SUBMARINE";
            const string path = @"..\..\Assets\S1C7.txt";

            var input    = Basic.Base64ToBytes(Basic.GetFileText(path));
            var keyBytes = Basic.AsciiToBytes(key);

            var message = Basic.Aes.RunAes(input, keyBytes, true);
            var control = Basic.Aes.MSDecryptAes128Ecb(input, keyBytes);

            Console.WriteLine(Basic.BytesToAscii(message));
            Assert.AreEqual(message, control);
        }
예제 #7
0
        public void TestIsLanguage()
        {
            const string path = @"..\..\Assets\TestIsEnglishDistributed.txt";

            string plaintext;

            using (var s = new StreamReader(path))
            {
                plaintext = s.ReadToEnd().ToLower();
            }

            var bytes = Basic.AsciiToBytes(plaintext);
            List <Tuple <double, byte, char> > matches;

            var score = Basic.IsLanguage(bytes, Basic.EnglishCharacterFrequencies, out matches);

            var keys = new Dictionary <byte, double>();

            Console.WriteLine("-- {0:P} similar to English character distribution --", score);
            foreach (var match in matches)
            {
                var key = Basic.Xor(Basic.AsciiToBytes(match.Item3 + ""), new[] { match.Item2 });
                if (keys.ContainsKey(key[0]))
                {
                    keys[key[0]] += match.Item1;
                }
                else
                {
                    keys.Add(key[0], match.Item1);
                }

                Console.WriteLine("Score: {0:P} - Char: {1} - Byte: {2} - Key: {3}",
                                  match.Item1, match.Item3,
                                  Basic.BytesToAscii(new[] { match.Item2 }),
                                  Basic.BytesToHex(key));
            }

            Console.WriteLine("\n-- Possible Keys --");
            foreach (var key in keys.OrderByDescending(x => x.Value))
            {
                Console.WriteLine("score: {0:P} - key: {1}", key.Value, Basic.BytesToHex(new[] { key.Key }));
            }
        }
예제 #8
0
        public void TestGetRepeatKeySplit()
        {
            const string message = "0000011111";

            Console.WriteLine("Message: {0}\n", message);

            var messageB = Basic.AsciiToBytes(message);
            var split2   = Basic.GetRepeatKeySplit(messageB, 2);
            var split5   = Basic.GetRepeatKeySplit(messageB, 5);

            Console.WriteLine("Split on 2key:\n");
            foreach (var split in split2)
            {
                Console.WriteLine(Basic.BytesToAscii(split));
            }

            Console.WriteLine("\nSplit on 5key:\n");
            foreach (var split in split5)
            {
                Console.WriteLine(Basic.BytesToAscii(split));
            }
        }