我有一个预定义的列表,里面写着两个列表:
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
然后我有一个加密的Caesar密码写成:
encryptionKey = 16
def passwordEncrypt (unencryptedMessage, encryptionKey):
encryptedMessage = ''
for symbol in unencryptedMessage:
if symbol.isalpha():
num = ord(symbol)
num += encryptionKey
if symbol.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif symbol.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26
encryptedMessage += chr(num)
else:
encryptedMessage += symbol
return encryptedMessage
我给用户一系列选择,其中一个选项提示用户输入新网站和他们想要的网站密码。我需要弄清楚如何使用passwordEncrypt()函数加密新密码,将新网站和新密码添加到新列表,然后将新列表添加到上面的“密码”列表中。这是我到目前为止:
if choice == '3':
print("What website is this password for?")
website = input()
print("What is the password?")
unencryptedPassword = input()
encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey)
这样编辑怎么样?
if choice == '3':
print("What website is this password for?")
website = input() #'test'
print("What is the password?")
unencryptedPassword = input() #'ABZZZA'
encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey)
#adding the new list(website, password) to the passwords list
passwords.append( [website, encryptedPassword] )
print(passwords)
结果:
[['yahoo', 'XqffoZeo'], ['google', 'CoIushujSetu'], ['test', 'QRPPPQ']]