题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
string_Encryption = input() string_Decryption = input() def Encryption(string_Encryption): result = '' for i in string_Encryption: if ord('a') <= ord(i) <=ord('z'): if ord(i) == ord('z'): result += 'A' else: result += chr(ord(i)+1-32) elif ord('A') <= ord(i) <= ord('Z'): if ord(i) == ord('Z'): result += 'a' else: result += chr(ord(i)+1+32) elif i.isdigit(): if i == '9': result += '0' else: result += str(int(i)+1) else: result += i return result def Decryption(string_Decryption): result = '' for i in string_Decryption: if ord('a') <= ord(i) <=ord('z'): if ord(i) == ord('a'): result += 'Z' else: result += chr(ord(i)-1-32) elif ord('A') <= ord(i) <= ord('Z'): if ord(i) == ord('A'): result += 'z' else: result += chr(ord(i)-1+32) elif i.isdigit(): if i == '0': result += '9' else: result += str(int(i)-1) else: result += i return result print(Encryption(string_Encryption)) print(Decryption(string_Decryption))