|
发表于 2022-1-5 00:33:05
|
显示全部楼层
本帖最后由 jackz007 于 2022-1-5 00:46 编辑
- def Crypt(s , x):
- r = ''
- d = 3 if x == 0 else -3
- for c in s:
- if 'A' <= c <= 'Z':
- r += chr(ord('A') + (ord(c) - ord('A') + d) % 26)
- elif 'a' <= c <= 'z':
- r += chr(ord('a') + (ord(c) - ord('a') + d) % 26)
- else:
- r += c
- return r
- x = input() . strip()
- if x:
- s1 = Crypt(x , 0) # 对 x 加密
- s2 = Crypt(s1 , 1) # 对 s1 解密
- print(s1)
- print(s2)
复制代码
运行实况:
- D:\00.Excise\Python>Python x.py
- Hello , World !
- Khoor , Zruog !
- Hello , World !
- D:\00.Excise\Python>
复制代码 |
|