print ("")
print ("Welcome to Vigenere cipher!")
print ("")
print ("This program will encrypt then offer you a decryption of your message.")
print ("")
print ("Start this off with inputting your message you would like to encrypt.")
m = input("")
print ("")
print ("Now enter your keyword you would like to use. (it must be (" +str(len(m)),"or less letters.))")
k = input("")
if len(k) > len(m):
print ("")
print ("sorry this is an invaild keyword")
print ("Please re-enter your keyword.")
k = input("")
else:
print ("Your keyword is great. Lets keep going")
print ("")
print ("Is this correct?")
print ("")
print("-------\n"
"Message: ",m,"\n"
"Key: ",k,
"\n-------")
print ("")
print ("yes or no")
correct = input ("")
if 'yes'.startswith(correct.lower()):
print("Great! Lets keep going.")
else:
print ("You previously put: " +str(m), " as your message.")
print ("Please re-enter the keyword you wish to use. (it must be (" +str(len(m)),"or less letters.))")
k = input("")
encrypted = ("")
print ("")
for a in m:
print ("The message letters are")
encrypt2 = ord(a)
for b in k:
print ("The keyword letters are")
encrypt = ord(b)
encrypt3 = (encrypt) + (encrypt2)
encrpyted = chr(encrypt3)
print (chr(encrypt3))
我需要它加密关键字,有什么帮助吗? p、 它需要像上面的代码一样基本。 是GCSE(英国) 如果它需要一些命令,那么你能告诉我它们是做什么的吗:)这样我就可以在任务中解释:)
首先,问题的失败:
所有的代码都是不必要的,这不是你的问题的一部分,你真正的问题是用vigenere密码算法加密一个字,这可以用两行代码来代替:
或者如果你愿意的话
注意:我重命名变量,以便帮助您的人更好地理解
因为输入现在不是问题,我可以解决这个问题
其次,算法失败:
最明显的错误是使用嵌套的
for
,越多越好,这会使您的解决方案复杂化,对于这个问题,您只需要一个for
第二个失败,是密码公式。。。。例如,第一个字母:
有了这些解释,现在我可以给出一个解决方案:
你会得到:
解释公式:
相关问题 更多 >
编程相关推荐