我编写了一个非常基本的加密程序,并且在为其编写解密算法时,我遇到了一些循环问题。
from re import *
cipher = open('cipher.txt')
ciphertext = cipher.read()
keyfile = open('key.txt')
key = keyfile.read()
decoded = []
chardec = ''
inval = 1
print("Decoder for encrypt1.py")
while inval == 1:
useManKey = input("Use a manual key? Y or N\n> ")
if useManKey == 'Y' or 'y':
key = input("Please enter the key you wish to use to decrypt\n> ")
inval = 0
elif useManKey == 'N' or 'n':
inval = 0
print("OK, decrypting")
else:
print("That wasn't a valid option/nPlease re-enter")
当我运行它并将 useManKey 声明为 N 或 n 时,它似乎运行循环的 if 部分,就好像我已将其声明为 Y 或 y 一样。我可能在这里很愚蠢,但任何帮助将不胜感激,谢谢。