-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathoctal.py
More file actions
31 lines (22 loc) · 1013 Bytes
/
octal.py
File metadata and controls
31 lines (22 loc) · 1013 Bytes
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
# -*- coding: UTF-8 -*-
"""Octal Codec - octal 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)
"""
from ..__common__ import *
__examples1__ = {
'enc(octal-spaced|octals_spaced)': {'this is a test': "164 150 151 163 40 151 163 40 141 40 164 145 163 164"},
}
__examples2__ = {
'enc(octal|octals)': {'this is a test': "164150151163040151163040141040164145163164"},
}
oct2 = lambda i: oct(i).lstrip("0").replace("o", "")
ENCMAP1 = {chr(i): oct2(i) for i in range(256)}
ENCMAP2 = {chr(i): oct2(i).zfill(3) for i in range(256)}
add_map("octal-spaced", ENCMAP1, sep=" ", pattern=r"^octals?[-_]spaced$", examples=__examples1__,
entropy=lambda e: .07258*e+2.3739, printables_rate=1.)
add_map("octal", ENCMAP2, pattern=r"^octals?$", examples=__examples2__, entropy=lambda e: .08803*e+2.19498,
printables_rate=1.)