我正在使用密码保护程序,并且有一个用于加密的Caesar密码:
# The encryption key for the Caesar Cipher
encryptionKey = 16
# Caesar Cipher Encryption
def passwordEncrypt (unencryptedMessage, key):
# We will start with an empty string as our encryptedMessage
encryptedMessage = ''
# For each symbol in the unencryptedMessage we will add an encrypted symbol
into the encryptedMessage
for symbol in unencryptedMessage:
if symbol.isalpha():
num = ord(symbol)
num += key
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
我有一个用于测试目的的预定义列表,其中包含两个网站及其加密密码:
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
我给用户一系列选择,选择#2让用户查找保存的密码,即:
if choice == '2': # Lookup a password
print("Which website do you want to lookup the password for?")
for keyvalue in passwords:
print(keyvalue[0])
passwordToLookup = input()
密码保护程序会加密密码,但是我只需要使用passwordEncrypt()函数来解密密码。