-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtap.py
More file actions
38 lines (27 loc) · 1.03 KB
/
tap.py
File metadata and controls
38 lines (27 loc) · 1.03 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
36
37
38
# -*- coding: UTF-8 -*-
"""Tap code - Tap/knock code 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 *
__examples__ = {
'enc(tap|knock-code|tap_code)': {'this is a test' : ".... ....⠀.. ...⠀.. ....⠀.... ...⠀ ⠀.. ....⠀.... ...⠀ ⠀. ."
"⠀ ⠀.... ....⠀. .....⠀.... ...⠀.... ...."},
}
__guess__ = ["tap", "tap-inv"]
def __build_encmap(a):
d, i = {}, 0
for x in range(1,6):
for y in range(1,6):
d[a[i]] = x * "." + " " + y * "."
i += 1
d['k'], d[' '] = d['c'], " "
return d
ENCMAP = {
'': __build_encmap("abcdefghijlmnopqrstuvwxyz"),
'inv': __build_encmap("abcdefghijlmnopqrstuvwxyz"[::-1]),
}
add_map("tap", ENCMAP, ignore_case="both", sep="⠀", pattern=r"^(?:tap|knock)(?:[-_]code)?(|inv)$")