python - 无法让我的函数执行任何操作

标签 python python-3.x

无论我如何安排返回或函数调用,都正在开发一个“加密”和“解密”输入字符串的程序。我觉得有些东西愚蠢地不合时宜,但我已经无计可施,无法让它真正做它需要做的事情。它将处理第一个输入问题,然后永远不会执行我要求它执行的功能。

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/

相关文章:

python - 将模型 ID 从整数更改为字母数字

python - HTML 表格特定行抓取

python - 在 python 中计算快速对数基数 2 上限

python - 我在settings.py上实现了电子邮件设置,但是当我提交表单时它不起作用

python - 在Python中匹配一大组(x,y)指向另一组具有异常值的点

Python3字节到十六进制字符串

python-3.x - 如何在python 3.5.2中读取avro文件

python - 从基于登录的网站抓取数据时如何避免被禁止?

python - SQLAlchemy:如何将作用域 session 绑定(bind)到请求

python - 使用 Flask Rest API 上传和处理文件