예제 #1
0
        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;
                }
            }
        }
예제 #2
0
        public void KasiskiExamination_Test()
        {
            var result1 =
                Kasiski.KasiskiExamination(
                    "PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU");

            var expected = new List <int> {
                2, 4, 8
            };

            CollectionAssert.AreEqual(expected, result1);
        }