Skip to content

Commit d8380ee

Browse files
committed
Added codec: galactic
1 parent 49c83a7 commit d8380ee

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![DOI](https://zenodo.org/badge/236679865.svg)](https://zenodo.org/badge/latestdoi/236679865)
1313
[![License](https://img.shields.io/pypi/l/codext.svg)](https://pypi.python.org/pypi/codext/)
1414

15-
This library extends the native [`codecs`](https://docs.python.org/3/library/codecs.html) library (namely for adding new custom encodings and character mappings) and provides a myriad of new encodings (static or parametrized, like `rot` or `xor`), hence its named combining *CODecs EXTension*.
15+
[**CodExt**](https://github.com/dhondta/python-codext) is a (Python2-3 compatible) library that extends the native [`codecs`](https://docs.python.org/3/library/codecs.html) library (namely for adding new custom encodings and character mappings) and provides **120+ new codecs**, hence its name combining *CODecs EXTension*. It also features a **guess mode** for decoding multiple layers of encoding and **CLI tools** for convenience.
1616

1717
```sh
1818
$ pip install codext
@@ -281,6 +281,7 @@ o
281281

282282
- [X] `braille`: well-known braille language (Python 3 only)
283283
- [X] `ipsum`: aka lorem ipsum
284+
- [X] `galactic`: aka galactic alphabet or Minecraft enchantment language (Python 3 only)
284285
- [X] `leetspeak`: based on minimalistic elite speaking rules
285286
- [X] `morse`: uses whitespace as a separator
286287
- [X] `navajo`: only handles letters (not full words from the Navajo dictionary)

codext/languages/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: UTF-8 -*-
22
from .braille import *
3+
from .galactic import *
34
from .ipsum import *
45
from .leetspeak import *
56
from .morse import *

codext/languages/galactic.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
"""Galactic Alphabet Codec - Minecraft enchantment language content encoding.
4+
5+
This codec:
6+
- en/decodes strings from str to str
7+
- en/decodes strings from bytes to bytes
8+
- decodes file content to str (read)
9+
- encodes file content from str to bytes (write)
10+
"""
11+
from ..__common__ import *
12+
13+
14+
__examples__ = {
15+
'enc-dec(galactic|minecraft_enchanting_language)': ["test " + MASKS['l']],
16+
'enc(galactic-alphabet|minecraft)': {'Bad test#': None},
17+
}
18+
19+
20+
# source: https://shapecatcher.com
21+
ENCMAP = {
22+
'a': ["ᒋ", "ᔑ"], 'b': ["⦣", "ゝ", "ʖ"], 'c': ["ì", "ᓵ"], 'd': "↸", 'e': ["ᒷ", "Ŀ"], 'f': ["𝌁", "⎓"],
23+
'g': ["𐌝", "┤", "⫞", "⊣"], 'h': ["₸", "⍑", "╤"], 'i': "╎", 'j': ["⫶", "⁝", "ⵗ", "⋮"], 'k': "ꖌ", 'l': "ꖎ",
24+
'm': ["ᒲ", "⟓"], 'n': ["ソ", "リ"], 'o': ["⁊", "フ", "ㇷ", "𝙹"], 'p': ["ⅱ", "ij", "‼", "!"],
25+
'q': ["ᑑ", "⊐", "コ"], 'r': ["⸬", "∷", "⛚"], 's': ["߆", "𝈿", "ꝇ", "ᓭ"], 't': ["ℸ", "ヿ", "⅂", "Ꞁ"],
26+
'u': ["⚍", "⍨"], 'v': ["𝍦", "⍊", "╧"], 'w': ["∴", "⸫", "⛬"], 'x': ["ꜘ", "╱", " ̷", "⟋"],
27+
'y': ["║", "‖", "∥", "ǁ", "𝄁", "|"], 'z': ["ᑎ", "⋂", "∩", "⨅", "⛫"],
28+
' ': [" ", "⠀"],
29+
}
30+
31+
32+
if PY3:
33+
add_map("galactic", ENCMAP, ignore_case="encode", printables_rate=0.,
34+
pattern=r"^(?:galactic(?:[-_]alphabet)?|minecraft(?:[-_](?:enchantment|enchanting[-_]language))?)$")
35+

docs/enc/languages.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ It supports letters, digits and some special characters.
2323

2424
-----
2525

26+
### Galactic
27+
28+
This implements the [Minecraft's enchanting table](https://www.thegamer.com/minecraft-enchantment-table-language-guide/) using resembling Unicode characters.
29+
30+
**Codec** | **Conversions** | **Aliases** | **Comment**
31+
:---: | :---: | --- | ---
32+
`galactic` | text <-> Minecraft enchantment symbols | `galactic-alphabet`, `minecraft_enchantment`, `minecraft-enchanting-language` | Python 3 only
33+
34+
```python
35+
>>> codext.encode("this is a test", "galactic")
36+
'ℸ₸╎߆ ╎߆ ᒋ ℸᒷ߆ℸ'
37+
>>> codext.decode("ℸ₸╎߆ ╎߆ ᒋ ℸᒷ߆ℸ", "galactic")
38+
'this is a test'
39+
```
40+
41+
-----
42+
2643
### Ipsum
2744

2845
This implements a codec that uses lorem ipsum words. It selects random words per letter and keeps the following punctuations: "`.,:;+=-*/\\`".

0 commit comments

Comments
 (0)