What is QiuYu?
It's a cypher that's mainly used in the titles of No.006's songs and on their site no006.org. It's a neat thing that really sparked my curiosity in implementing a tool that could do this for universally any language.
It works by representing tones via [1..4]:
u1ch.ing2m.ao4y.en4ch.ao3zin normal pinyin would bechu1 ming2 yao4 chen4 zao3.
The same can be applied to other languages, e.g. English:
Hello world->ello@h.orld@w- Side note: the numbers in pinyin function as a delimiter. Because
there are no tones nor diacritics in English,
@is used as one.
In both cases the first letter (or initial) of a word moves to the
back, behind the delimiter, and words are separated by . instead of a space.
These two are already working systems on their site, but I'd like to extend it a bit.
Supported languages
- Chinese (pinyin)
- English
Usage
./qiuyu [-e | -d] [-l <language>] <text>-eencrypt (default)-ddecrypt-llanguage, the name of a file inlangs/without the extension (default:english)
./qiuyu -l english -e "Hello world" # ello@h.orld@w
./qiuyu -l english -d "ello@h.orld@w" # Hello world
./qiuyu -l pinyin -e "chu1 ming2 yao4" # u1ch.ing2m.ao4yRun it from the project root, since langs/ is looked up relative to the working
directory.
Building
QiuYu needs CCDJIT
(the language files are compiled at runtime), built beforehand with
./build.sh release.
make CCDJIT=/path/to/ccdjit
make check # loads every langs/*.c once to catch compile errorsHow languages work
Every file in langs/ is a language.
They are not part of the program: qiuyu
compiles langs/<name>.c with CCDJIT
when -l <name> is given, so adding a
language needs no rebuild.
A language file includes lang.h and
defines two functions. Both return a malloc'd string, or NULL on failure:
char *lang_encrypt(const char *input);
char *lang_decrypt(const char *input);Do not define main in a language file,
it is added automatically.
lang.h also provides a small toolkit,
since every language boils down to finding a delimiter and reordering
the pieces:
SB: a growable string buffer (sb_init,sb_append,sb_push,sb_take,sb_free)Span: a view into a string, so pieces can be moved around without copyingsplit_spans/sb_join_spans: split on a delimiter and join back
Tests
make check runs every sample in samples.txt through the matching language file.
Each sample is encrypted, compared with the expected ciphertext (if one
is given), decrypted again, and compared with the original.
A line is language|plaintext with an
optional third field |ciphertext:
english|Hello world|ello@h.orld@w
pinyin|ni3 hao3|i3n.ao3h
- Blank lines and lines starting with
#are ignored. - The language is the file name in
langs/without the extension. - With a ciphertext the exact output is checked too. Without one, only the round trip is.
- A language file with no samples gets a warning.
- Use about 10 samples per language, and cover its edge cases: digraphs, syllables or words that pass through unchanged, single letters.
- English plaintext must start with a capital and contain no other capitals, because decrypt capitalizes the first letter of the output.
Adding a language
- Create
langs/<name>.c. The name may only containa-z,0-9and_. - Write up the rules.
- Add about 10 samples to
samples.txtand runmake check. - Add it to the list of supported languages.
