def guess_key3(cipher_text, word1, word2, word3): #变了点 letter_frequency = get_letter_frequency(cipher_text.lower()) excluded_letters = [letter for letter in letter_frequency.keys() if letter_frequency[letter] == 0] sorted_letters = sorted([letter for letter in letter_frequency.keys() if letter_frequency[letter] > 0], key=lambda x: letter_frequency[x], reverse=True) print("Excluded letters:", excluded_letters) print() f1 = ['a', 'i', 'r'] f2 = ['t', 'o', 'n'] f3 = ['s', 'l', 'c'] f4 = ['u', 'p', 'm', 'd', 'h'] f5 = ['g', 'b', 'y', 'f'] f6 = ['v', 'w','k'] f7 = ['x', 'z', 'q', 'j'] mf = [f6, f5, f4, f3, f2, f1] key = {sorted_letters[0]: 'e'} most_common_letters_m = [sorted_letters[19:22],sorted_letters[15:19] ,sorted_letters[10:15] ,sorted_letters[7:10] ,sorted_letters[4:7], sorted_letters[1:4]] c1 = 0.7 for i1 in range(5): lk1=len(key) key1 =check3(cipher_text, word1, word2, word3, most_common_letters_m, sorted_letters, mf, f7, lk1, key, c1, i1) key.update(key1) del mf[-1] del most_common_letters_m[-1] c1+=0.2 return key def check3(cipher_text, word1, word2, word3, most_common_letters_m, sorted_letters, mf, f7, key, lk1, c1, i1): mp = [[j for j in range(len(mf[i]))] for i in range(len(mf))] row_permutations = [itertools.permutations(row) for row in mp] matrix_permutations = itertools.product(*row_permutations) for permutation in matrix_permutations: for i in range(len(mp)): for j in range(len(mp[i])): key[most_common_letters_m[i][permutation[i][j]]] = mf[i][j] if len(key) < len (sorted_letters): for i in range (len(sorted_letters)-len(key)): key.update({sorted_letters[len(key)+i-1]:f7[i]}) decrypted_text = decrypt(cipher_text, key) k1 = is_plaintext3(decrypted_text, word1, word2 ,word3) #k2 = k1 if k1 > k2 else k2 if( k1 > c1): key1 = dict(list(key())[lk1:len(mp[i])+lk1]) return key1 def is_plaintext3(text, word1, word2 ,word3): words_found = 0 for word in text.split(): if word.lower() in word1: words_found += 10 if word.lower() in word2: words_found += 3 if word.lower() in word3: words_found += 1 return words_found / len(text.split()) def decrypt(cipher_text, key): mapping_dict = str.maketrans(key) return cipher_text.translate(mapping_dict)这段代码的问题
时间: 2024-04-07 10:28:37 浏览: 122
key_DES.rar_blowfish cipher
这段代码中的 `check3` 函数在定义时参数列表中包含了六个参数,但在调用时只传递了九个参数,因此会导致参数数量不匹配的错误。具体来说,`check3` 函数在调用时缺少了 `lk1`、`key`、`c1`、`i1` 这四个参数。你需要检查一下代码逻辑,确认这四个参数的值应该从哪里传递进去,并在调用时将它们添加到参数列表中。
阅读全文