题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
# 处理过程 def process_data(target, isencrypt=True): res = [] for item in target: if item.isalpha(): if isencrypt: if item.islower(): if ord(item) ==122: res.append(chr(97).upper()) else: res.append(chr(ord(item)+1).upper()) if item.isupper(): if ord(item.lower()) ==122: res.append(chr(97)) else: res.append(chr(ord(item.lower())+1)) else: if item.islower(): if ord(item) ==97: res.append(chr(122).upper()) else: res.append(chr(ord(item)-1).upper()) if item.isupper(): if ord(item.lower()) ==97: res.append(chr(122)) else: res.append(chr(ord(item.lower())-1)) elif item.isdigit(): if isencrypt: if int(item) == 9: res.append('0') else: res.append(str(int(item) + 1)) else: if int(item) == 0: res.append('9') else: res.append(str(int(item) - 1)) else: res.append(item) return ''.join(res) # 加密 def encrypt(target): return process_data(target) # 解密 def decrypt(target): return process_data(target, False) print(encrypt(input())) print(decrypt(input()))#字符串加解密#