我是Python的新手,我不认为我完全理解我得到的'no attribute‘错误消息,我想知道是否有人能给我一些提示,或者更好地解释我在'alphabet’变量中遗漏了什么。
import caesar
def loadDictionary():
dictionary = {}
file = open('dictionary.txt')
for word in file.read().split('\n'):
dictionary[word.upper()] = None
file.close
return dictionary
DICTIONARY = loadDictionary()
def isEnglish(plaintext):
matchingWords=0
words = plaintext.split(' ')
for word in words:
if word.upper() in DICTIONARY:
matchingWords += 1
return matchingWords / len(words) >= 0.6
def bruteForce(cihertext):
for key in range(len(caesar.alphabet)):
plaintext = caesar.caesar(ciphertext, key, 'd')
if isEnglish(plaintext):
print('Key: ' + str(key) + 'Plaintext = ' + plaintext)
return None
ciphertext = 'Qefp'
bruteForce(ciphertext)发布于 2020-01-30 14:05:26
这意味着caesar模块不包含任何叫做“字母表”的东西。在文档或其源代码中查找正确的名称。考虑到在python中,所有变量名都是区分大小写的。
https://stackoverflow.com/questions/59979860
复制相似问题