コード例 #1
0
     for keyLen in mostLikelyKeysKasiski[:2]:
         # Split the message into keyLen columns        
         msgColumns = polyCi.msgSplit(msg, keyLen)
         # holds the potential keyword
         keyword = ""
         # perform frequency analysis on each column
         print "Using the Vigenere Square on the top 4 most frequent letters in each column assuming that each corresponds to 'e' results in the following options:"                
         for idx, column in enumerate(msgColumns):
             # get the most frequent letter in the column
             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: