hrtest.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:crypto 作者: erose1337 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号