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

时间:2016-02-10 02:53:06

标签: python python-3.x

使用"加密"和#34;解密"一个输入字符串,无论我如何安排我的返回或函数调用。我觉得某些东西是愚蠢的不合适的,但我知道我的智慧最终让它实际上做了它需要的东西。它会经历第一个输入问题,然后再执行我要求的功能。

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

1 个答案:

答案 0 :(得分:3)

您可以尝试更改这两行:

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上),加密器运行得很漂亮:)