不能让我的功能做任何事情

2024-04-20 00:01:15 发布

您现在位置:Python中文网/ 问答频道 /正文

不管我如何安排我的返回或函数调用,处理一个“加密”和“解密”输入字符串的程序。我觉得有些东西是愚蠢的不合适,但我在我的智囊团有这个实际上做它需要的。它将遍历第一个输入问题,然后从不执行我要求它执行的函数。你知道吗

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()

Tags: tokeyinforifelseprintchr
1条回答
网友
1楼 · 发布于 2024-04-20 00:01:15

您可以尝试更改以下两行:

EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strDecryptedInput,"= ",strEncryptedOutput, " Key = ",key)

为了这个

strEncryptedOutput = EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strInput,"= ",strEncryptedOutput, " Key = ", str(intKeyInput))

我用这些修改运行了您的代码(在python3.5.1上),加密程序运行得很好:)

相关问题 更多 >