#作者:zonei123 2020/4/15
#置换密码:a<--->e b<--->f c--->g d<--->h ..... w<--->a x<--->b y<--->c z<--->d
import math
#声明类
class Cipher:
#加密模块
def encrypt(self):
piw = input("请输入密码(任意小写字母组合):")
cipher_text = ' '
for i in piw:
if 'a' <= i <= 'z':
cipher_text += chr(ord('a') + ((ord(i) - ord('a')) + 4) % 26)
print("密文:",cipher_text)
#解密模块
def decrypt(self):
cipher_text = input("请输入密文(任意小写字母组合):")
piw = ' '
for i in cipher_text:
if 'a' <= i <= 'z':
piw += chr(ord('a') + ((ord(i) - ord('a')) + 4) % 26)
print("密码:", piw)
#退出模块
def tuichu(self):
return 0
#主程序
print("|-------------------------------|")
print(" 欢迎使用加解密程序")
print("|-------------------------------|")
print(" 1.加密")
print(" 1.解密")
print(" 3.退出")
choice = input('请选择功能菜单(1-3):')
CIP = Cipher()
if choice == '1':
CIP.encrypt()
elif choice == '2':
CIP.decrypt()
elif choice == '3':
CIP.tuichu()
python简单置换加密解密程序
最新推荐文章于 2024-05-08 10:31:15 发布