培根密码(Bacon)——python解密
简介
培根密码,⼜名倍康尼密码(英语:Bacon’scipher)是由法兰西斯·培根发明的⼀种隐写术。
特点:
培根密码本质上是将⼆进制信息通过样式的区别,加在了正常书写之上。培根密码所包含的信息可以和⽤于承载其的⽂章完全⽆关。培根密
码实际上就是⼀种替换密码,根据所给表⼀⼀对应转换即可加密解密。它的特殊之处在于:可以通过不明显的特征来隐藏密码信息,⽐如
⼤⼩写、正斜体等,只要两个不同的属性,密码即可隐藏。
实现
培根密码实际上就是⼀种替换密码,⼀般有两种加密⽅式,所以相互对应就可以了。
代码
函数
letters1=[
'A','B','C','D','E','F','G',
'H','I','J','K','L','M','N',
'O','P','Q','R','S','T',
'U','V','W','X','Y','Z',
]
letters2=[
'a','b','c','d','e','f','g',
'h','i','j','k','l','m','n',
'o','p','q','r','s','t',
'u','v','w','x','y','z',
]
cipher1=[
"aaaaa","aaaab","aaaba","aaabb","aabaa","aabab","aabba",
"aabbb","abaaa","abaab","ababa","ababb","abbaa","abbab",
"abbba","abbbb","baaaa","baaab","baaba","baabb",
"babaa","babab","babba","babbb","bbaaa","bbaab",
]
cipher2=[
"AAAAA","AAAAB","AAABA","AAABB","AABAA","AABAB","AABBA",
"AABBB","ABAAA","ABAAA","ABAAB","ABABA","ABABB","ABBAA",
"ABBAB","ABBBA","ABBBB","BAAAA","BAAAB","BAABA",
"BAABB","BAABB","BABAA","BABAB","BABBA","BABBB",
]
defbacon1(string):
lists=[]
#分割,五个⼀组
foriinrange(0,len(string),5):
(string[i:i+5])
#print(lists)
#循环匹配,得到下标,对应下标即可
foriinrange(0,len(lists)):
forjinrange(0,26):
iflists[i]==cipher1[j]:
#print(j)
print(letters1[j],end="")
print("")
defbacon2(string):
lists=[]
#分割,五个⼀组
foriinrange(0,len(string),5):
(string[i:i+5])
#print(lists)
#循环匹配,得到下标,对应下标即可
foriinrange(0,len(lists)):
forjinrange(0,26):
iflists[i]==cipher2[j]:
#print(j)
print(letters2[j],end="")
print("")
主函数
importBacon
if__name__=="__main__":
1("aababababbaaaaaaabba")
2("AABABABABAAAAAAAABBA")
总结
这个我很少遇到,不太常见。
本文发布于:2022-12-29 01:26:30,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/50257.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |