Skip to content

Commit 3142e3f

Browse files
committed
Added codec: klopf
1 parent 91d0637 commit 3142e3f

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ o
182182
`gzip` | text <-> Gzip-compressed text | standard Gzip compression/decompression
183183
`html` | text <-> HTML entities | implements entities according to [this reference](https://dev.w3.org/html5/html-author/charref)
184184
`ipsum` | text <-> latin words | aka lorem ipsum
185+
`klopf` | text <-> klopf encoded text | Polybius square with trivial alphabetical distribution
185186
`leetspeak` | text <-> leetspeak encoded text | based on minimalistic elite speaking rules
186187
`letter-indices` | text <-> text with letter indices | encodes consonants and/or vowels with their corresponding indices
187188
`manchester` | text <-> manchester encoded text | XORes each bit of the input with `01`

codext/stegano/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: UTF-8 -*-
2+
from .klopf import *
23
from .resistor import *
34
from .sms import *
45
from .whitespace import *

codext/stegano/klopf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: UTF-8 -*-
2+
"""Klopf Codec - Polybius-based 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(klopf|klopfcode)': {'this is a test': "44324234 4234 11 44513444"},
15+
}
16+
17+
18+
ENCMAP = {"ABCDEFGHIKLMNOPQRSTUVWXYZ"[y*5+x]: "".join([str(x+1), str(y+1)]) for x in range(5) for y in range(5)}
19+
ENCMAP['J'] = "43"
20+
ENCMAP[' '] = " "
21+
22+
23+
add_map("klopf", ENCMAP, ignore_case="both", pattern=r"^(?:klopf(?:code)?)$", printables_rate=1.)
24+

docs/enc/stegano.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
-----
44

5+
### Klopf Code
6+
7+
This is a Polybius code with the trivial alphabetical distribution ("A" -> (1,1), "B" -> (2,1), ...). This can be tested [here](https://gc.de/gc/klopfcode/).
8+
9+
**Codec** | **Conversions** | **Aliases** | **Comment**
10+
:---: | :---: | --- | ---
11+
`klopf` | text <-> klopf encoded text | `klopfcode` |
12+
13+
```python
14+
>>> codext.encode("this is a test", "klopf")
15+
'44324234 4234 11 44513444'
16+
>>> codext.decode("44324234 4234 11 44513444", "klopf")
17+
'THIS IS A TEST'
18+
```
19+
20+
-----
21+
522
### Resistor Color Codes
623

724
This uses the [electronic color code](https://en.wikipedia.org/wiki/Electronic_color_code#Resistor_color-coding) to encode digits, displaying colors in the terminal with ANSI color codes.

0 commit comments

Comments
 (0)