培根密码,培根所用的密码是一种本质上用二进制数设计的,没有用通常的0和1来表示,而是采用a和b
一、培根密码加密方式
第一种方式:
A aaaaa B aaaab C aaaba D aaabb E aabaa F aabab G aabba H aabbb I abaaa J abaab
K ababa L ababb M abbaa N abbab O abbba P abbbb Q baaaa R baaab S baaba T baabb
U babaa V babab W babba X babbb Y bbaaa Z bbaab
第二种方式
a AAAAA g AABBA n ABBAA t BAABA
b AAAAB h AABBB o ABBAB u-v BAABB
c AAABA i-j ABAAA p ABBBA w BABAA
d AAABB k ABAAB q ABBBB x BABAB
e AABAA l ABABA r BAAAA y BABBA
f AABAB m ABABB s BAAAB z BABBB
二、举例
例1、 baabaaabbbabaaabbaaaaaaaaabbabaaaabaaaaaabaaabaabaaaabaabbbaabbbaababb
baaba aabbb abaaa bbaaa aaaaa abbab aaaab aaaaa abaaa baaba aaaba abbba abbba ababb
s h i y a n b a i s c o o l
例2、明文是LOVE,用“随意选取句子和文”加密,得到密文就是“SuLyi XuanQ uJuZi HEwEN”(这里用大写字母代表a,小写字母代表b)
SuLyi XuanQ uJuZi HEwEN
ababbabbbabababaabaa
这里,加密者使用两种不同字体,准备好一篇包含相同ab字数的假信息后,即两种字体分别代表a型和b型。然后假信息中的每个字母按字体来决定其代表“a”还是“b”。
例3、明文:now is a good t.........密码术 密码学 密码论坛 密码术论坛, `, Q" J/ K2 F9 S
n o w i s a g o o d t
abbaa abbab babaa abaaa baaab aaaaa aabba abbab abbab aaabb baaba
密文:BOWED ASTER PINED JOKED THEIR BLACK HASTE ARRAY INSET CHEST SLING
加密规则:(1)a-m -> a ,也就是说 a ——m 的所有字母都能替换成 a。
n-z -> b ,也就是说 n ——z 的所有字母都能替换成 b。
(2)a-m <- a ,也就是说 a 可以替换 a——m 中的任何一个字母。
n-z <- a ,也就是说 b 可以替换 n——z 中的任何一个字母。
Ps:密文中的单词都是根据加密规则随便拼凑出来的,为了使加密更隐蔽,一般拼凑出来的单词可连成通顺的一句话
三、附加解密Python脚本如下:
#!/usr/bin/python # -*- coding: utf-8 -*- import re alphabet = ['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'] first_cipher = ["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"] second_cipher = ["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"] def encode(): string = raw_input("please input string to encode: ") e_string1 = "" e_string2 = "" for index in string: for i in range(0,26): if index == alphabet[i]: e_string1 += first_cipher[i] e_string2 += second_cipher[i] break print "first encode method result is: "+e_string1 print "second encode method result is: "+e_string2 return def decode(): e_string = raw_input("please input string to decode: ") e_array = re.findall(".{5}",e_string) d_string1 = "" d_string2 = "" for index in e_array: for i in range(0,26): if index == first_cipher[i]: d_string1 += alphabet[i] if index == second_cipher[i]: d_string2 += alphabet[i] print "first decode method result is: "+d_string1 print "second decode method result is: "+d_string2 return if __name__ == '__main__': while True: print " *******Bacon Encode_Decode System*******" print "input should be lowercase,cipher just include a b" print "1.encode 2.decode 3.exit" s_number = raw_input("please input number to choose ") if s_number == "1": encode() raw_input() elif s_number == "2": decode() raw_input() elif s_number == "3": break else: continue
----------------------------------------------------------------分割线---------------------------------------------------------
ps:萌新一枚,本文纯为学习笔记,以防某日犯傻忘记--。如有不妥处,望大佬们赐教~