该代码核心思想为采用makeTrans函数随机生成映射表,经过多次映射,相当于一个多表置换密码。
将英文字符换成梵文,效果类似于佛曰加密(不知道原始网站代码出自哪里,在这里贴的为百度到的第一个网站http://hi.pcmoe.net/buddha.html)
#加密
#维吉尼亚密码
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("请输入待加密数据:")
CT1 = text.translate(table1)
CT2 =CT1.translate(table2)
CT =CT2.translate(table3)
print("密文是:%s" % CT)
CT =input("请输入待解密数据:")
print(CT.translate(table3_1).translate(table2_1).translate(table1_1))
效果如下: