static void Main(string[] args) { //Example Enciphered Text const string cipherText = "Ar op chmrivv tfh ofvx nyneiksfnv cxsvu dc ysxjvv zszg di lgqg rhoagg kltl M'xv fxwr vlvgari fzxj mp dc farf vzxj wkegx. \"Olgeiowv afy ywin cmdw gtzxbumbzrz sra frx,\" zi vfpw ei, \"llwm jiovquwv vyem spn klx hiqgpx ar vyml ostch aszge'x ash vyi tvzcextyiu kltl cql'zx zef.\""; //Example of how to execute a known plaintext attack _log.Info("-------- KNOWN PLAINTEXT ATTACK --------"); var possibleKeys = KnownPlaintextAttack.AttackWithKnownPlaintext(cipherText, "the"); foreach (var key in possibleKeys) { _log.InfoFormat("Possible Key: {0}", key); _log.InfoFormat(VigenereEngine.Decipher(cipherText, key)); } //Example of how to execute a Kasiski/Babbage Analysis & Attack _log.Info("-------- KASISKI ATTACK --------"); var likelyKeyLengths = Kasiski.KasiskiExamination(cipherText); foreach (var keyLength in likelyKeyLengths) { _log.InfoFormat("Attempting hack with key length {0} ({1} possible keys)", keyLength, Math.Pow(Convert.ToDouble(keyLength), Convert.ToDouble(Constants.NumMostFreqLetters))); var foundKey = KasiskiAttack.AttackWithKeyLength(cipherText, keyLength); if (!string.IsNullOrEmpty(foundKey)) { _log.InfoFormat("Decrypted Text: {0}", new Vigenere().Decipher(cipherText, foundKey)); System.Console.ReadKey(); return; } } }
public void AttackWithKnownPlaintext_Test() { var actual = KnownPlaintextAttack.AttackWithKnownPlaintext( "Llkj ml s xgjx llvkek mg fg lwxv ajvr mwwvzrz llg Mmzwrgii Vatjvv mgsnj", "testing"); var expected = new List <string> { "SECRET" }; CollectionAssert.AreEqual(expected, actual); }