在 python 中编写一个 vigenere 密码,我完全迷失了,有人愿意帮我一把,并提出可以改进/使其正常工作的事情吗?目前我遇到了各种各样的错误
letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print ("This program will take a keyword, and use it to encrypt plaintext.")
def keyword():
print ("Please enter your keyword")
keyword = input()
return keyword
def plaintext():
print ("Please enter your plaintext")
plaintext = input()
return plaintext
def translate (keyword, plaintext):
keywordtwo=0
number=0
keyword=keyword.upper()
length = len(plaintext)
lengthtwo=len(keyword)
for symbol in plaintext:
number=letters.find(symbol.upper())
if number!=-1:
number+=letters.find
num%=len(letters)
if symbol.isupper():
translated.append(letters[number])
elif symbol.islower():
translated.append(letters[number].lower())
if keywordtwo==len(keyword):
keywordtwo=0
else:
translated.append(symbol)
return ' '.join(translated)
keyword = keyword()
plaintext = plaintext()
translated = translate(keyword, plaintext)
print ("Your new text is:")
print (translate(keyword, plaintext))