将新列表添加到预定义列表

Adding a new list to a pre-defined list

我有一个预定义的列表,里面有两个列表,写成:

passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]

然后我有一个用于加密的 Caeser Cipher 写成:

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() 函数加密新密码,将新网站和新密码都添加到新列表中,然后将该新列表添加到上面的 "passwords" 列表中。这是我目前所拥有的:

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']]