def encrypt(string, new_string):
i = 0
if i < len(string):
if ord(string[i]) > 65 and ord(string[i]) < 97:
new_string = string[i] + encrypt(string[1:], new_string)
if ord(string[i]) >= 97 or ord(string[i]) == 32:
if not(ord(string[i])) == 32:
x = ord(string[i])
x = x + 1
y = chr(x)
new_string = new_string + y
new_string = encrypt(string[1:], new_string)
else:
new_string = new_string + ' '
new_string = encrypt(string[1:], new_string)
return new_string
string = input("Enter a message: \n")
new_string = ''
print("Encrypted message:")
print(encrypt(string, new_string))
如果有多个大写字母,它将在加密消息的前面输出大写字母。
例如:“Hello World”变为“HWfmmp psme”。但是,输出应该是“Hfmmp Xpsme”