-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_bacon.py
82 lines (80 loc) · 1.6 KB
/
decode_bacon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#/usr/bin/python2
#coding = utf - 8
import codec
import string
tbl = {
"AAAAA": "a",
"AAAAB": "b",
"AAABA": "c",
"AAABB": "d",
"AABAA": "e",
"AABAB": "f",
"AABBA": "g",
"AABBB": "h",
"ABAAA": "i",
"ABAAB": "j",
"ABABA": "k",
"ABABB": "l",
"ABBAA": "m",
"ABBAB": "n",
"ABBBA": "o",
"ABBBB": "p",
"BAAAA": "q",
"BAAAB": "r",
"BAABA": "s",
"BAABB": "t",
"BABAA": "u",
"BABAB": "v",
"BABBA": "w",
"BABBB": "x",
"BBAAA": "y",
"BBAAB": "z"
}
def decode_bacon(dt):
splt = [dt[i: i + 5]
for i in range(0, len(dt), 5)
]
cc = ""
for ss in splt:
print ss
cc += tbl[ss]
print cc
return cc
d = codecs.open("english_breakfast.txt", "rb", encoding = 'utf-8').read()
caps = u "𝐚𝐛𝐜𝐝𝐞𝐟𝐠𝐡𝐢𝐣𝐤𝐥𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐭𝐮𝐯𝐰𝐱𝐲𝐳𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙"
norm = string.ascii_lowercase + string.ascii_uppercase
p4 = ""
unpart4 = ""
for i in d:
c = i
ii = caps.find(i)
if ii != -1:
p4 += 'B'
c = norm[ii]
else :
p4 += 'A'
unpart4 += c
p3 = ""
unpart3 = ""
for i in unpart4:
c = i
if c in string.ascii_uppercase:
p3 += 'B'
c = string.lower(c)
else :
p3 += 'A'
unpart3 += c
p2 = ""
for i in unpart3:
if (ord(i) - ord('a')) % 2 == 0:
p2 += 'A'
else :
p2 += 'B'
p1 = ""
for i in unpart3:
if (ord(i) - ord('a')) < 13:
p1 += 'A'
else :
p1 += 'B'
print decode_bacon(p1) + decode_bacon(p2) + decode_bacon(p3) +
decode_bacon(p4)