Skip to content

Commit a6a6090

Browse files
committed
Added codec: rick
1 parent 78e2566 commit a6a6090

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ o
301301

302302
- [X] `klopf`: aka Klopf code ; Polybius square with trivial alphabetical distribution
303303
- [X] `resistor`: aka resistor color codes
304+
- [X] `rick`: aka Rick cipher (in reference to Rick Astley's song "*Never gonna give you up*")
304305
- [X] `sms`: also called _T9 code_ ; uses "`-`" as a separator for encoding, "`-`" or "`_`" or whitespace for decoding
305306
- [X] `whitespace`: replaces bits with whitespaces and tabs
306307
- [X] `whitespace_after_before`: variant of `whitespace` ; encodes characters as new characters with whitespaces before and after according to an equation described in the codec name (e.g. "`whitespace+2*after-3*before`")

codext/stegano/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: UTF-8 -*-
22
from .klopf import *
33
from .resistor import *
4+
from .rick import *
45
from .sms import *
56
from .whitespace import *
67

codext/stegano/rick.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: UTF-8 -*-
2+
"""Rick Astley Codec - Rick Astley's song 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(rick|rick-astley)': {'this is a test': "TELL LET You gonna + You gonna + NEVER + TELL UP gonna TELL"},
15+
}
16+
17+
18+
# inspired from: https://github.com/moongazer07/rick-cipher
19+
ENCMAP = {
20+
'A': "NEVER", 'B': "GONNA", 'C': "GIVE", 'D': "YOU", 'E': "UP", 'F': "Never", 'G': "Gonna", 'H': "LET", 'I': "You",
21+
'J': "DOWN", 'K': "NEver", 'L': "GOnna", 'M': "TURN", 'N': "AROUND", 'O': "AND", 'P': ["DESERT", "DESSERT"],
22+
'Q': "YOu", 'R': "NEVer", 'S': "gonna", 'T': "TELL", 'U': "A", 'V': "LIE", 'W': "and", 'X': "HURT", 'Y': "you",
23+
'Z': "rick astley", ' ': "+", '.': ".", '\n': "\n",
24+
'0': "0", '1': "1", '2': "2", '3': "3", '4': "4", '5': "5", '6': "6", '7': "7", '8': "8", '9': "9",
25+
}
26+
27+
28+
add_map("rick", ENCMAP, "?", " ", ignore_case="encode", pattern=r"^rick(?:[-_]astley)?(?:[-_]cipher)?$",
29+
printables_rate=1.)
30+

docs/enc/stegano.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ This uses the [electronic color code](https://en.wikipedia.org/wiki/Electronic_c
3838

3939
-----
4040

41+
### Rick Cipher
42+
43+
This converts letters to words from Rick Astley's famous song "*Never gonna give you up*".
44+
45+
**Codec** | **Conversions** | **Aliases** | **Comment**
46+
:---: | :---: | --- | ---
47+
`rick` | text <-> words from Risk's song | `rick-astley`, `rick_cipher`, `rick-astley-cipher` | case-insensitive while encoding
48+
49+
```python
50+
>>> codext.encode("Test String", "rick")
51+
'TELL UP gonna TELL + gonna TELL NEVer You AROUND Gonna'
52+
>>> codext.decode("TELL UP gonna TELL + gonna TELL NEVer You AROUND Gonna", "rick")
53+
'TEST STRING'
54+
```
55+
56+
-----
57+
4158
### SMS (T9)
4259

4360
This codec implements the SMS encoding, also caled T9, that is the conversion from characters to their corresponding phone keystrokes.

0 commit comments

Comments
 (0)