static void ExperimentTextLength(StreamWriter streamWriter) { streamWriter.WriteLine("KeyLength;TextLength;Probability"); foreach (var keyLength in KEY_LENGTHS) { for (int i = 250; i <= 3000; i += 250) { var correct = 0.0; for (int j = 0; j < N; ++j) { var key = _keyGenerator.GetKey(keyLength); var text = _textGenerator.GetText(i); var encryptedText = _vigenereEncryption.Encrypt(text, key); var guess = _vigenereBreaker.BreakCipher(encryptedText); if (guess.ToUpper() == key.ToUpper()) { ++correct; } } streamWriter.WriteLine($"{keyLength};{i};{correct / N}"); Console.WriteLine($"{keyLength};{i};{correct / N}"); } } }
public void EncryptMultipleStringsTest() { List <string> textToEncrypt = new List <string>() { "ATTACKATDAWN", "ATTACKATDAWN", "ATTACKATDAWN" }; string key = "LEMON"; List <string> expected = new List <string>() { "LXFOPVEFRNHR", "LXFOPVEFRNHR", "LXFOPVEFRNHR" }; IEnumerable <string> result = _encryptor.Encrypt(textToEncrypt.AsEnumerable(), key); Assert.AreEqual(expected, result); }