题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
def encode(inStr): outStr = "" for i in inStr: ord_i = ord(i) if 64 < ord_i < 90: ord_i += 33 elif ord_i == 90: ord_i = 97 elif 96 < ord_i < 122: ord_i -= 31 elif ord_i == 122: ord_i = 65 elif 47 < ord_i < 57: ord_i += 1 elif ord_i == 57: ord_i = 48 outStr += chr(ord_i) return outStr def decode(inStr): outStr = "" for i in inStr: ord_i = ord(i) if ord_i == 65: ord_i = 122 elif 65 < ord_i < 91: ord_i += 31 elif ord_i == 97: ord_i = 90 elif 97 < ord_i < 123: ord_i -= 33 elif 48 < ord_i < 58: ord_i -= 1 elif ord_i == 48: ord_i = 57 outStr += chr(ord_i) return outStr i1 = input() i2 = input() #print("a:%d, z:%d, A:%d, Z:%d, 0:%d, 9:%d" % (ord("a"), ord("z"), ord("A"), ord("Z"), ord("0"), ord("9"))) print(encode(i1)) print(decode(i2))