Example #1
0
        public void Challenge4_Solution()
        {
            var inputFile = new StreamReader("Assets/inputForChallenge4.txt");

            var results = new Dictionary <string, double>();

            while (!inputFile.EndOfStream)
            {
                var encryptedLine = Converter.FromHexStringToByteArray(inputFile.ReadLine().Trim());

                var key = SingleByteXorCipher.FindSingleByteKey(encryptedLine);

                var decryptedText = SingleByteXorCipher.Decrypt(encryptedLine, key);

                var score = SingleByteXorCipher.ScoreAccordingToEnglishLetterFrequency(Encoding.Default.GetBytes(decryptedText));

                results.Add(decryptedText, score);
            }

            var hiddenMessage = results.OrderByDescending(x => x.Value).First();

            Assert.AreEqual("Now that the party is jumping\n", hiddenMessage.Key);

            Console.WriteLine($"Score:{hiddenMessage.Value}");
        }
Example #2
0
        public void Challenge3_Solution()
        {
            var inputByteArray = Converter.FromHexStringToByteArray(_hexStringInput);

            var key = SingleByteXorCipher.FindSingleByteKey(inputByteArray);

            Assert.AreEqual('X', Convert.ToChar(key));

            var decryptedText = SingleByteXorCipher.Decrypt(inputByteArray, key);

            Assert.AreEqual("Cooking MC's like a pound of bacon", decryptedText);
        }