-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathordinal.py
More file actions
28 lines (20 loc) · 918 Bytes
/
ordinal.py
File metadata and controls
28 lines (20 loc) · 918 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
# -*- coding: UTF-8 -*-
"""Ordinal Codec - ordinal 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(ordinal-spaced|ordinals_spaced)': {'this is a test': "116 104 105 115 32 105 115 32 97 32 116 101 115 116"},
}
__examples2__ = {
'enc(ordinal|ordinals)': {'this is a test': "116104105115032105115032097032116101115116"},
}
ENCMAP1 = {chr(i): str(i) for i in range(256)}
ENCMAP2 = {chr(i): str(i).zfill(3) for i in range(256)}
add_map("ordinal-spaced", ENCMAP1, sep=" ", pattern=r"^ordinals?[-_]spaced$", examples=__examples1__, entropy=3.,
printables_rate=1.)
add_map("ordinal", ENCMAP2, pattern=r"^ordinals?$", examples=__examples2__, entropy=3., printables_rate=1.)