题解 | #字符串加解密#

字符串加解密

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))

全部评论

相关推荐

jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务