Code
Reading a text without its key: naming the cipher, peeling off encodings, counting letters, measuring an unknown script, breaking nomenclators, reading messages in depth, replaying the Enigma breaks, checking anagrams.
Layer Decoder
Peels a text encoded several times over. Each step tries the decoders whose alphabet fits — Base64, Base32, Base58, Ascii85, hex, binary, URL, HTML entities, quoted-printable, Morse, tap code, Bacon, A1Z26, NATO — the keyless ciphers ROT13, Caesar, Atbash, ROT47 and one-byte XOR, and gzip, then follows the outputs that read most like English, as GCHQ’s CyberChef does with its Magic operation.
Terms
History, how it works, how it was checked, limits
History
Base64, Base32 and hexadecimal are defined in RFC 4648 (S. Josefsson, 2006), and the gzip format in RFC 1952 (P. Deutsch, 1996). Base64 is the commonest wrapping for data sent as text, and puzzles lay several encodings over one message. GCHQ’s CyberChef finds encoded data with its Magic operation; this tool follows that plan, with its own measures.
How it works
A best-first search peels a layer at a time. Text gets every decoder whose alphabet fits, nineteen in all — Base64, Base32, Base58, Ascii85, hex, binary, decimal and octal bytes, URL encoding, HTML entities, escapes, quoted-printable, Morse, tap code, Bacon, A1Z26, NATO, data URLs and JSON Web Tokens — and up to three transforms that keep the alphabet: ROT13, Caesar’s best shift, Atbash, ROT47 and reversal. Bytes are inflated if gzip or zlib; bytes that read badly get the one-byte XOR key that reads best. Each output is scored by English quadgram fluency, discounted where few characters are letters; a capture-the-flag flag adds much, a recognised file type scores as a result. A reading must beat 20 runs of the same search on the text’s characters shuffled, each among its kind, a transform costing 12, a long text judged on its first 1,000; without a /regex/ sought, both run off the page. Look for stops at a text or /regex/. The search is drawn as its tree, the reading shown in gold.
How it was checked
Twenty-two cases are pinned: Base64 under and over hex, ROT13, gzip, Base32, reversal, ROT47 and one-byte XOR (key 0x5A found); Caesar (shift 7 found); URL encoding; Morse; a flag; a PNG and a GIF; plain English, left alone; short messages in Base64, ROT13, Morse and hex; the tree holds each case’s steps. Look for stops at a text or /regex/; inflation, at its cap. Random bytes in Base64, spaced binary, hex between colons, %-escapes and Morse read no more often than chance’s one in 21.
The tests hold 54 checks of this tool; 2 rest on outside material:
- Another’s computation Layers written by Python’s gzip, base64 and binascii are taken off in their order: hex, Base64, gzip
- Another’s computation … and Python’s zlib under its Base32: Base32, zlib
Limits
The score reads English alone, so a Caesar, ROT13, Atbash or XOR layer over another language can be missed. XOR is tried with one-byte keys only, and no keyword cipher: Vigenère and the like have their own tools. Bacon is read in his 24-letter alphabet. The search stops at 500 readings or ten layers, and the input at 1 MB. A text that reads best as it is, or no better than its shuffles, has nothing to peel: twelve letters in ROT13 can.