题解 | #字符串加解密#

字符串加解密

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

全部评论

相关推荐

2024-11-19 15:16
武汉理工大学 Java
喀什克尔的胡杨:秋招面了很多主管,感觉主管都是傻蛋
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务