题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
def encrypt(s1): s1_encrypt='' #加密结果 for i in s1: if i.isupper(): if ord(i)==90: s1_encrypt += chr(ord('a')) else: s1_encrypt += chr(1+ord(i.lower())) elif i.islower(): if ord(i)==122: s1_encrypt += chr(ord('A')) else: s1_encrypt += chr(1+ord(i.upper())) elif i.isdigit(): if ord(i)==57: s1_encrypt += chr(ord('0')) else: s1_encrypt += chr(1+ord(i)) else: s1_encrypt += i print(s1_encrypt) def decrypt(s2): s2_decrypt='' #解密结果 for i in s2: if i.isupper(): if ord(i)==65: s2_decrypt += chr(ord('z')) else: s2_decrypt += chr(ord(i.lower())-1) elif i.islower(): if ord(i)==97: s2_decrypt += chr(ord('Z')) else: s2_decrypt += chr(ord(i.upper())-1) elif i.isdigit(): if ord(i)==48: s2_decrypt += chr(ord('9')) else: s2_decrypt += chr(ord(i)-1) else: s2_decrypt += i print(s2_decrypt) while 1: try: s1=input() s2=input() encrypt(s1) decrypt(s2) except: break