无论我如何安排返回或函数调用,都正在开发一个“加密”和“解密”输入字符串的程序。我觉得有些东西愚蠢地不合时宜,但我已经无计可施,无法让它真正做它需要做的事情。它将处理第一个输入问题,然后永远不会执行我要求它执行的功能。
def DecryptMe(strEncryptedInput):
for key in range(1,101):
strDecrypt = strEncryptedInput
strDecryptedOutput = ''
for c in strDecrypt:
if (ord(c) - key < 32):
DecryptedInteger =((ord(c) - key) + 127 - 32)
strDecryptedOutput = strDecryptedOutput + chr(DecryptedInteger)
else:
DecryptedInteger = (ord(c) - key)
strDecryptedOutput = strDecryptedOutput + chr(DecryptedInteger)
print(key,"= ",strDecryptedOutput)
def EncryptMe(strDecryptedInput,key):
strEncrypt = strDecryptedInput
strEncryptedOutput = ''
for c in strEncrypt:
if (ord(c) - key < 32):
EncryptedInteger = ((ord(c) + key) - 127 + 32)
strEncryptedOutput = strEncryptedOutput + chr(EncryptedInteger)
else:
EncryptedInteger = (ord(c) + key)
strEncryptedOutput = strEncryptedOutput + chr(EncryptedInteger)
return strEncryptedOutput
strChoice = input("Please either chose to (E)ncrypt or (D)ecrypt a message.")
if strChoice == "e" or strChoice == "E":
strDecrypedInput = ""
strInput = input("Please type the string you wish to encrypt and press the Enter key.")
intKeyInput = int(input("Please enter a key from 1 to 100 to encrypt the message with."))
EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strDecryptedInput,"= ",strEncryptedOutput, " Key = ",key)
elif strChoice == "d" or strChoice =="D":
print("")
else:
print("")
#key = 88
#DecryptMe(":mmZ\dxZmx]Zpgy")
#EncryptMe(strDecryptedInput,key)
Mode()
最佳答案
您可以尝试更改这两行:
EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strDecryptedInput,"= ",strEncryptedOutput, " Key = ",key)
到此
strEncryptedOutput = EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strInput,"= ",strEncryptedOutput, " Key = ", str(intKeyInput))
我通过这些修改运行了您的代码(在 Python 3.5.1 上),加密器运行得非常漂亮:)
关于python - 无法让我的函数执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35306018/