【发布时间】:2019-07-20 14:56:14
【问题描述】:
我有一个预定义的列表,里面有两个列表,写成:
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
然后我有一个用于加密的凯撒密码,写成:
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)
【问题讨论】:
-
passwords += [[website, encryptedPassword]]
标签: python python-3.x list encryption caesar-cipher