forked from dhondta/python-codext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbacon.py
More file actions
executable file
·36 lines (27 loc) · 1.24 KB
/
Copy pathbacon.py
File metadata and controls
executable file
·36 lines (27 loc) · 1.24 KB
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
# -*- coding: UTF-8 -*-
"""Bacon's Cipher Codec - bacon content encoding.
This codec:
- en/decodes strings from str to str
- en/decodes strings from bytes to bytes
- decodes file content to str (read)
- encodes file content from str to bytes (write)
Reference: https://en.wikipedia.org/wiki/Bacon%27s_cipher
"""
from ..__common__ import *
__examples__ = {
'enc(bacon|bacon_cipher|baconian-cipher|bacon-ab|bacon_AB)': {
'this is a test': "baabaaabbbabaaabaaab abaaabaaab aaaaa baabaaabaabaaabbaaba",
},
'enc(bacon-01|bacon_01)': {
'this is a test': "10010001110100010001 0100010001 00000 10010001001000110010",
},
}
__guess__ = {"bacon", "bacon-ba", "bacon-01", "bacon-10"}
ENCMAP = {
'A': "aaaaa", 'B': "aaaab", 'C': "aaaba", 'D': "aaabb", 'E': "aabaa", 'F': "aabab", 'G': "aabba", 'H': "aabbb",
'I': "abaaa", 'J': "abaaa", 'K': "abaab", 'L': "ababa", 'M': "ababb", 'N': "abbaa", 'O': "abbab", 'P': "abbba",
'Q': "abbbb", 'R': "baaaa", 'S': "baaab", 'T': "baaba", 'U': "baabb", 'V': "baabb", 'W': "babaa", 'X': "babab",
'Y': "babba", 'Z': "babbb", ' ': " ",
}
add_map("bacon", ENCMAP, ignore_case="both", pattern=r"bacon(?:(?:ian)?[-_]cipher)?([\-_].{2})?$", expansion_factor=5.,
printables_rate=1.)