Skip to content

Commit 5bd3261

Browse files
committed
Added new codec: tomtom
1 parent 0b70b83 commit 5bd3261

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This library extends the native `codecs` library and provides some new encodings
3434
`scytale` | text <-> scytale ciphertext | encrypts with L, the number of letters on the rod (belongs to [1,[)
3535
`shift` | text <-> shift(N) ciphertext | shift ordinals with N (belongs to [1,255])
3636
`sms` | text <-> phone keystrokes | also called T9 code ; uses "`-`" as a separator for encoding, "`-`" or "`_`" or whitespace for decoding
37+
`tomtom` | text <-> tom-tom encoded text | similar to `morse`, using slashes and backslashes
3738
`url` | text <-> URL encoded text | aka URL encoding
3839
`xor` | text <-> XOR(N) ciphertext | XOR with a single byte (N belongs to [1,255])
3940
`whitespace` | text <-> whitespaces and tabs | replaces bits with whitespaces and tabs

codext/languages/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
from .braille import *
33
from .morse import *
44
from .radio import *
5+
from .tomtom import *
56

codext/languages/tomtom.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: UTF-8 -*-
2+
"""Tom-Tom Codec - tom-tom content encoding.
3+
4+
This codec:
5+
- en/decodes strings from str to str
6+
- en/decodes strings from bytes to bytes
7+
- decodes file content to str (read)
8+
- encodes file content from str to bytes (write)
9+
"""
10+
from ..__common__ import *
11+
12+
13+
__examples__ = {
14+
'enc': {
15+
'this is a test': "\\\\/\\ /\\\\ /\\\\\\ \\/\\ | /\\\\\\ \\/\\ | / | \\\\/\\ /\\ \\/\\ \\\\/\\"
16+
}
17+
}
18+
19+
20+
ENCMAP = {
21+
# letters
22+
'A': "/", 'B': "//", 'C': "///", 'D': "////", 'E': "/\\", 'F': "//\\", 'G': "///\\", 'H': "/\\\\", 'I': "/\\\\\\",
23+
'J': "\\/", 'K': "\\\\/", 'L': "\\\\\\/", 'M': "\\//", 'N': "\\///", 'O': "/\\/", 'P': "//\\/", 'Q': "/\\\\/",
24+
'R': "/\\//", 'S': "\\/\\", 'T': "\\\\/\\", 'U': "\\//\\", 'V': "\\/\\\\", 'W': "//\\\\", 'X': "\\\\//",
25+
'Y': "\\/\\/", 'Z': "/\\/\\",
26+
# word separator
27+
' ' : "|",
28+
}
29+
30+
31+
add_map("tomtom", ENCMAP, ".", " ", ignore_case="both", pattern=r"^tom-?tom([-_]?.{2})?$")
32+

docs/encodings.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ This codec implements the SMS encoding, also caled T9, that is the conversion fr
308308

309309
-----
310310

311+
### Tom-Tom
312+
313+
This codec is similar to morse. It converts text into slashes and backslashes.
314+
315+
**Codec** | **Conversions** | **Aliases** | **Comment**
316+
:---: | :---: | --- | ---
317+
`tomtom` | text <-> tom-tom encoded text | `tom-tom` | uses "`|`" as a separator
318+
319+
```python
320+
>>> codext.encode("this is a test", "tom-tom")
321+
'\\\\/\\ /\\\\ /\\\\\\ \\/\\ | /\\\\\\ \\/\\ | / | \\\\/\\ /\\ \\/\\ \\\\/\\'
322+
>>> codext.decode("\\\\/\\ /\\\\ /\\\\\\ \\/\\ | /\\\\\\ \\/\\ | / | \\\\/\\ /\\ \\/\\ \\\\/\\", "tomtom")
323+
'THIS IS A TEST'
324+
```
325+
326+
-----
327+
311328
### URL
312329

313330
This handles URL encoding, regardless of the case when decoding and with no error.

0 commit comments

Comments
 (0)