str1 = "abcdefghi,.;:jklmnop!qrstuvwxyz12 346578ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str2 = "klmnopqr12s3t,A:5;B.X6DE8!FGH 7IJKL4MNOPQRSTUVWXYZuvwxyzabcdefghij"
str3 = "tuvwxy1za2AB3XD7EFG8,.;:HI5JK6!LMNO4PQRS TUVWXYZbcdefghijklmnopqrs"
str4 = "klmn1op3qr4ab5AB7XD,.;:EF8GHI6J KLM2NOPQRST!UVWXYZcdefghijstuvwxyz"
table1 = str.maketrans(str1,str2)
table2 = str.maketrans(str2, str3)
table3 = str.maketrans(str3, str4)
table1_1 = str.maketrans(str2, str1)
table2_1 = str.maketrans(str3, str2)
table3_1 = str.maketrans(str4, str3)
text = input ("请输入待加密数据:")
AS1 = text.translate(table1)
AS2 = AS1.translate(table2)
AS = AS2.translate(table3)
print("密文是:%s" % AS)
AS = input("请输入待解密数据:")
print(AS.translate(table3_1).translate(table2_1).translate(table1_1))
效果如下
请输入待加密数据:123456
密文是:KM20N
请输入待解密数据:422322
.44h44