1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| import os
def encryption(): m = input("请输入明文:") k =int(input("位移值:")) s = m.lower() l = list(s) st = l i = 0 while i < len(l): if ord(l[i]) < 123-k: st[i] = chr(ord(l[i]) + k) else: st[i] = chr(ord(l[i]) + k - 26) i = i+1 print ("加密结果为:"+"".join(st)) def decryption(): m= input("请输入密文:") k = int(input("位移值:")) s = m.lower() l = list(s) st = l i = 0 while i < len(l): if ord(l[i]) >= 97+k: st[i] = chr(ord(l[i]) - k) else: st[i] = chr(ord(l[i]) + 26 - k) i = i+1 print ("解密结果为:"+"".join(st)) while True: encryption() decryption()
|