def crack_monoalphabetic_substitution_cipher(ciphertext, dictionary):
lowercase_ascii = string.lowercase
ciphertext_words = sorted(ciphertext.split(), key=len)
sorted_dictionary = sorted(dictionary, key=len)
biggest_word_size = len(ciphertext_words[-1])
key = {}
searching = True
for ciphertext_word in (bytearray(word) for word in reversed(sorted_dictionary)):
word_size = len(ciphertext_word)
for branch, dictionary_word in enumerate((bytearray(word) for word in
reversed(sorted_dictionary) if
len(word) == word_size)):
for index, letter in enumerate(dictionary_word):
try:
key[branch][letter] = ciphertext_word[index]
except KeyError:
_key = bytearray(26)
_key[letter] = ciphertext_word[index]
key[branch] = _key
评论列表
文章目录