esolang
Learn · Ideas273 languages show it

Encoding tricks

The same program, written down a different way. Change the encoding and you change who can read it, how long it is, and what a typo does.

●○○ easy · where to see it

The idea

Many esolangs are an existing language in a new costume. The machine underneath is unchanged; only the way instructions are written changes. Brainfuck alone has hundreds of these. Many are jokes, but they show something real. An encoding is a choice, and it decides what the program looks like to everything that reads it, people, compilers and mutations alike.

Read the story

Common tricks.

  • Substitution. Swap each symbol for a word. Ook! (David Morgan-Mar) writes Brainfuck's > as Ook. Ook? and + as Ook. Ook..
  • Counting. Make the instruction a number of things. In Chicken the number of chicken words on a line is the opcode.
  • Length only. Unary and Lenguage turn a Brainfuck program into one huge number, and the program is that many characters. The content is ignored.
  • Invisible. Whitespace uses only space, tab and newline.
  • Differences. Piet programs are images; an instruction is the change in hue and lightness from one colour block to the next.
  • Compression. Seed stores a length and a random seed. A Mersenne Twister generator expands them into a Befunge-98 program, which is then run.
  • Arithmetic. Fractran keeps all its registers in one integer, as exponents of primes. Binary lambda calculus (John Tromp) writes lambda terms as bits; 00 is a lambda, 01 an application, 1…10 a variable.
  • Encryption. Malbolge decodes each instruction from its byte and its position in memory, so the same character means different things in different places.

How it works

Unary, step by step (Lode Vandevenne, 2005).

Unary, step by step (Lode Vandevenne, 2005). Each Brainfuck command gets three bits.

><+-.,[]
000001010011100101110111

Take the program ,. (read a character, print it).

  1. The codes in order are , = 101 and . = 100.
  2. Put a 1 in front, so leading zeros are not lost, giving 1 101 100.
  3. Read it as binary, 1101100 = 64 + 32 + 8 + 4 = 108.
  4. The Unary program is 108 zeros.

To run it, count the zeros, write the count in binary, drop the leading 1 and read off the codes. Every extra command multiplies the length by 8, so Hello World in Unary has more characters than there are atoms in the observable universe. The encoding is complete and utterly impractical.

Lenguage is the same idea with any characters and its own table; only the length counts.

What a typo does. Encodings differ most in their neighbourhoods, meaning which programs are one small change away.

Encoding of "add 72"One-character change gives
Brainfuck: + × 72add 71 or add 73 (delete or add one +)
Decimal: ADD 72add 2, 7, 12, 79, 702, …
Unary lengtha completely different program

Unary changes value in tiny steps; decimal jumps around; a length-encoding scrambles everything.

Seen in

Try this

  1. Encode the Brainfuck program +. in Unary. How many zeros? (Answer: 84.)
  2. Decode a Unary program of 1,000 zeros. Is it a valid Brainfuck program?
  3. Hard: design an encoding of numbers as text where every one-character change moves the value by at most 1. What does it cost in length?

Further

Where to see it

Ook!UnaryLenguageChickenWhitespacePietSeedMalbolgeBinary lambda calculusFRACTRAN'1066'1L_a2DFuck2L'99'Acc!!ACLADJUSTAEWNNAheuiAlphaprintArithmeticArselasdfAsigAssembleiBAM128Base2e15textBeatnikBedtimeBeetsBenulBespokebftreeBinary InsanityBinerdybinoduBitBouncebitchBitChangerBitShiftBittyLangBitwise TranceBoolfuckBoredBrailleBraincrashBrainfishBrainfuckBrainfuckestBrainPiBrainthonBrainwhirlBRUHBubblegumBueueBunk bedBuzzFizzCalligulan AssemblyCalScriptCerberusCharcoalCheesecakeChicken chicken chicken: chicken chickenChipCholcCinnamon GumCipherCodonCompositeCompressedBFConglumentCounterfishCryptenCubicallyCurlyfrickDaydreamDDRDeadchickenDeadfish xDecimal'Del|m|t'DFA-erDNA#DOBELADodosDominoScriptDotfuckDStackDuck Duck GooseDuocentehexaquinquagesimalEcstaticEINEEmojiCoderEnsemencerETAExaminable Invocation VectorEXCONFactorFakeScriptferNANDoFlipbitFoldersFor The WorthyForeachFuncitonFunctasyFyshGbagboGödelangGödelfishGoldfuckGolfTextGopherGOTO 10Grocery ListHanabiHardfishHashedPoemHeckHell69HexagridHexspHGFTSNOAHow dare you fuck the brainHow to learn this languageHS.:iI1l!¡IndirectIntegerInvertedJellyJotKeyFKonamiCodeLASTLinecodeLocksmithLogicGates/exGatesLogicodeLS BasicMalbrainMeawLangMemory GAPMetatapeMezzoMinimMiniStringFuckMmmm()MoaiscriptMorse Assembly Languageμ6Multiplicitynameless languageNeimnibletNo Literals, Gotos Only, Final Destination!NoNoobinaryNoodle SoupNORNTFJNULL-NONE NOTHING'NULL'Numbernya~rgsNybblangO_oObfuscatedObfuscatedFuckoOo CODEPainfuckPaRappaParenthesis HellParentheticPDA-erPenisPicoPixiedustPlusOrOutputPNPLPoeticPolynomialPopFuckPrimesprocessor.txtPTotEPuzzlangPyfunPyhton [sic]PZABQoiblQWERTY Keyboard Dot LanguageRationalRelationsRESOLRETURNRing-around-the-RosieRNARockstarRottenS₅SakuraSemper dissolubilisSesosShakespeare'#b'';#+'SiteripSlamsmall s.c.r.i.p.t.':)'SommeSoundSpaces and tabsSplitSpoonSRStairCaseStandard ChessStarryStoplightThe Temporary StackTheLangtinyBFTrailTrigbf improvedTrigbfTriggerTruTtttTurkeyTwo FourTwocoman🐢!$_$$!(?!)...啊!彳亍掉爆子脑操脑菜就多练这不是编程语言!靈符¿UglyBFUnarianUndecimalUnicatUniversal LambdaUpDownV (FMota)VarnandVelatoVerboseFuckVoidPtrv^vW.W.EWASDWidthWoodchuckwsadwsfx-DXcf4••XSVLyupZZucchiniBefunge-98