为什么在解密程序中出现有关字符串的错误?

时间:2019-08-29 21:48:22

标签: python python-3.x encryption

我正在尝试进行某种解密。该程序要求您输入一个短语,它将对其解密。例如,如果我输入“ hi”,则应显示为“ ef”。但是,我得到的只是一个错误,TypeError:-的不支持的操作数类型:'str'和'str'

我不确定该怎么办,我尝试摆弄代码,但收效不佳。

def plainText(string):
    cipher = ''
    for i in string:
        if i == ' ':
            cipher = cipher - i
        elif i.isupper():
            cipher = cipher + chr((ord(i) - 3 - 65) % 26 + 65)
        else:
            cipher = cipher + chr((ord(i) - 3 - 97) % 26 + 97)
    return cipher
message = input("What's your message?")
print("Your decrypted message is: ", plainText(message))
print("Your original message was: ", message)```

Again, the error was

TypeError: unsupported operand type(s) for -: 'str' and 'str' at line 7. 

Thank you in advance!

0 个答案:

没有答案