Translate human-speak to ghost-speak and vice versa.
- Install Python.
- Clone this repository, or just download
ghost-translator.py
. - Mark
ghost-translator.py
as executable withchmod +x ghost-translator.py
to run it directly, or run it withpython3 ghost-translator.py (parameters)
The JS implementation is available to use online through GitHub Pages. If you want to download and use on your computer:
- Clone or download this repository
- Open
ghost-translator.html
in your web browser - Use the provided textarea and buttons to encode/decode your spooky messages
ghost-translator.py -d (or --decode) "OoOooo OoO OOooO OoooooO"
- Decode ghost-speakghost-translator.py -e (or --encode) "Hello!"
- Encode ghost-speak
Examples:
$ ./ghost-translator.py -e "Boo! 👻"
OoooOo OOOO OOOO OoooooO Ooooooo OOOOOoOoooooOOoOO
$ ./ghost-translator.py -d "OoOooo O Ooooo Ooooo OOooO Ooooooo OoOooo O OOoo OOoo OOOO OoOOO OoO OoO OOOo OoooooO Ooooooo OOOOOooOOOOOoooOO"
Happy Halloween! 🎃
It's quite simple, really. To encode human-speak into ghost-speak, first each character of the entered string is converted into its integer Unicode code point. This integer is then XORed with 96 (01100000). This is done to shorten the resulting binary string, as all lower case characters (a-z) have their binary representations start with 011
. This also produces variable-length strings, by stripping out leading zeroes, which I think look nicer than fixed-width, 8 character binary strings. The integer is then converted into a binary string, and the prefix 0b
is stripped. Finally, each character in the binary string is iterated through and converted to o
or O
: ones become upper case Os, and zeroes become lower case Os.
This process is repeated for every character entered, with a space appended between each ghost word to represent the boundary between each character.
To decode ghost-speak back to human-speak, the process is simply done in reverse. The implementation is the same across language versions.
If emoji aren't involved, the two implementations will yield identical results. If emoji are involved, JS and Python will give different results when encoding or decoding. It looks like this is because Python considers the double-byte emoji to be a single character, while JavaScript considers them to be two characters.
Inspired by Cow translator by SkwalExe 🐮