第一次发布。 我有一个学校作业,我试图从塞萨尔的密码解密密码。 我被赋予了工作的职责。我不知道如何得到加密密钥的相反值
编辑,这是我的代码。我不知道你需要什么,所以大部分都在这里
import csv
import sys
#The password list - We start with it populated for testing purposes
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
#The password file name to store the passwords to
passwordFileName = "samplePasswordFile"
#The encryption key for the caesar cypher
encryptionKey=16
#Caesar Cypher 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
def loadPasswordFile(fileName):
with open(fileName, newline='') as csvfile:
passwordreader = csv.reader(csvfile)
passwordList = list(passwordreader)
return passwordList
def savePasswordFile(passwordList, fileName):
with open(fileName, 'w+', newline='') as csvfile:
passwordwriter = csv.writer(csvfile)
passwordwriter.writerows(passwordList)
if(choice == '2'): #Lookup at password
print("Which website do you want to lookup the password for?")
for keyvalue in passwords:
print(keyvalue[0])
passwordToLookup = input()
for keyvalue in passwords:
website = keyvalue[0]
password = keyvalue[1]
if website == passwordToLookup:
encryptionKey = encryptionKey -16
passwordEncrypt(password, encryptionKey)
print(password)
我试过多种方法,但还是不能得出结论
目前没有回答
相关问题 更多 >
编程相关推荐