class TestDecryptString(unittest.TestCase): def setUp(self): self.msg = VigenereCipher(KEY, CIPHERTEXT) def test_isinstance(self): self.assertIsInstance(self.msg, VigenereCipher) def test_isequals(self): check = self.msg.decrypt() expect = PLAINTEXT self.assertEquals(check, expect)
columnFrequencies = letFreq.getFrequencies(''.join(column))[1] mostFrequentLetTuple = columnFrequencies[0] mostFreqLet = mostFrequentLetTuple[0] # for tuple in columnFrequencies[:4]: # print vigCi.vigenereSquareDecrypt(tuple[0], 'e') # print "options above" print "Column", idx+1, [vigCi.vigenereSquareDecrypt(tuple[0], 'e') for tuple in columnFrequencies[:6]] # assuming this letter corresponds to 'e', use the vigenere square # to discover the original keyword letter keywordLet = vigCi.vigenereSquareDecrypt(mostFreqLet, 'e') keyword += keywordLet # I discovered this to be the keyword through analyzing the possible combinations across the columns # and put it in manually to make the output more interesting #keyword = 'funny' print "\nPotential keyword: %s" % keyword print "Message deciphered using keyword '%s':\n%s\n" % (keyword, vigCi.decrypt(msg,keyword)) else: print "\nKasiski test failed (no repeated substrings with length >= 3)" kasiskiFailed = True mostLikelyKeyIC = polyCi.getKeywordLength(len(msg), msgIC) print "\nMost likely key length using IC test: %0.4f" % (mostLikelyKeyIC) if kasiskiFailed: print "\nAssuming that message was enciphered using a hill cipher." HillSystem().super_decrypt(msg, None, zeroSystem=True) # 2. For the ones which you guess to be monoalphabetic, do the following: else: # (a) Run frequency analysis to determine which letters most likely correspond to "e" and "t". # (b) Use these correspondences to find the key. # (c) Decrypt the message. plaintext = monCi.decrypt(msg, verbose=True)