培根密碼解密筆記
培根密碼,培根所用的密碼是一種本質上用二進制數設計的,沒有用通常的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:\n") 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:\n"+e_string1 print "second encode method result is:\n"+e_string2 return def decode(): e_string = raw_input("please input string to decode:\n") 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:\n"+d_string1 print "second decode method result is:\n"+d_string2 return if __name__ == ‘__main__‘: while True: print "\t*******Bacon Encode_Decode System*******" print "input should be lowercase,cipher just include a b" print "1.encode\n2.decode\n3.exit" s_number = raw_input("please input number to choose\n") if s_number == "1": encode() raw_input() elif s_number == "2": decode() raw_input() elif s_number == "3": break else: continue
註:本筆記參考文獻百度百科、xuqi7博客、 曜希JFSH
----------------------------------------------------------------分割線---------------------------------------------------------
ps:萌新一枚,本文純為學習筆記,以防某日犯傻忘記--。如有不妥處,望大佬們賜教~
培根密碼解密筆記