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}"); }
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); }
public void SingleByteXorCipher_Test() { // assign string input = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"; string key = null; string expected = "Cooking MC's like a pound of bacon"; // execute string actual = SingleByteXorCipher.Decrypt(input, out key); // assert, ignore case Assert.IsNotNull(actual); Assert.IsNotNull(key); Assert.AreEqual(expected, actual, true); System.Diagnostics.Debug.WriteLine("------------------"); System.Diagnostics.Debug.WriteLine(actual); System.Diagnostics.Debug.WriteLine("------------------"); }