Breadcrumb
Malbolge: The Language That Rewrites Itself
Table of Contents
Ben Olmstead designed Malbolge in 1998 as a deliberately hostile, public-domain esoteric programming language, with difficulty as its goal. It is a tiny ternary virtual machine disguised as printable text: programs use base-three arithmetic, have only eight effective instructions, and rewrite their own instructions while they run. The name comes from Malebolge, the eighth circle of Hell in Dante’s Inferno, where fraud is punished.1
Its rules are compact once you treat it as a virtual machine. It would still make a poor web server.
A language built to resist its users
Malbolge was influenced by earlier difficult languages such as Brainfuck, Befunge, and INTERCAL. Olmstead pushed their awkwardness much further by combining unusual arithmetic with encrypted, self-altering code. The design also plays on the relationship between language, obfuscation, and cryptography.
The first working “Hello, world!” program reportedly took two years to find. It was generated by Andrew Cooke using a beam-search program, not typed by a person. Lou Scheffer later published a cryptanalysis of Malbolge and an explanation of its instruction cycles, which made systematic programming much more practical. A correct implementation of “99 Bottles of Beer” did not appear until 2005.2
One caveat applies to its reputation: standard Malbolge has a fixed memory of 59,049 cells, so it is a bounded-storage machine rather than a Turing-complete language. The variant Malbolge Unshackled, created in 2007, removes that limit and is Turing complete. Programs written for ordinary Malbolge do not necessarily run unchanged in Unshackled.3
How the virtual machine works
Malbolge source looks like ASCII noise because it is close to machine code. The virtual machine has:
- 59,049 memory cells, numbered from 0 to 59,048. Every cell stores a 10-trit ternary word.
- An accumulator named
a. - A code pointer named
c. - A data pointer named
d.
All three registers start at zero. Code and data share the same memory, and every address wraps around modulo 59,049.
Before execution, whitespace is removed from the source and each remaining character is copied into memory. The rest of memory is initialized from the previous two cells using the language’s peculiar crazy operation. This initialization pattern repeats every twelve cells. The reference interpreter and the written specification differ in a few edge cases; this post follows the reference interpreter.4
Decoding an instruction
The value stored at the current code pointer does not directly name an operation. Malbolge first computes
(mem[c] + c) mod 94
and maps that result through a 94-character lookup table. The eight meaningful results map to these operations:
| Decoded value | Normalized op | Effect |
|---|---|---|
| 4 | i | Jump: set c = mem[d] |
| 5 | < | Output the accumulator as one byte |
| 23 | / | Read one byte into the accumulator |
| 39 | * | Rotate mem[d] one trit to the right; copy the result to a |
| 40 | j | Set d = mem[d] |
| 62 | p | Apply crazy to a and mem[d]; store in both |
| 68 | o | Do nothing |
| 81 | v | Halt |
Those letters are also used by “normalized Malbolge”, a human-readable assembly notation. They are not what ordinary Malbolge source contains. In raw source, the character needed at position c depends on both the operation and the address, which is one reason the same operation looks different throughout a program.
After most instructions execute, the code cell at c is transformed through a fixed substitution table and both c and d are incremented. A jump is especially devious: it changes c before the encryption step, so the machine encrypts the jump target, then increments c and resumes at mem[d] + 1. The code that runs is therefore not a fixed list of instructions; it is a sequence that changes in response to its own execution.
The crazy operation
The p instruction combines the accumulator and a memory cell trit by trit. For each pair of ternary digits, it uses this table:
memory \ a | 0 | 1 | 2 |
|---|---|---|---|
| 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 2 |
| 2 | 2 | 2 | 1 |
The operation has no familiar addition or XOR equivalent. Together with self-modification, it makes ordinary control flow hard to recognize and gives the language its cryptanalytic flavor.
Run a real Malbolge program
Here is a classic “Hello, world.” program. The editor below runs a small interpreter in your browser, using the reference semantics. Click Run program, or edit the source and experiment. Execution is local to this page and is limited to one million VM steps so an accidental infinite loop does not freeze the tab.
Ready. The classic program prints Hello, world.
The complete visible source is only one line:
(=<`#9]~6ZY327Uv4-QsqpMn&+Ij"'E%e{Ab~w=_:]Kw%o44Uqp0/Q?xNvL:`H%c#DD2^WV>gY;dts76qKJImZkj
It prints Hello, world. with a period, not an exclamation mark. There is no recognizable print statement in that line. The output appears only after character values have been decoded through the instruction table, modified by register operations in the data area, and streamed through the < instruction.
Generate Malbolge from text
Most experiments do not need hand-written Malbolge machine code. Generators can search for a program with the execution behavior you want.
Option 1: use a browser, no installation
Malbolge Tools by zb3 is the quickest place to start. It includes both an interpreter and several code generators.
- Open the generator tab.
- Enter the text you want the program to print, for example
Hi, Malbolge!. - Choose Linear generator (fastest) for quick results, or Branch-on-read generator when you want shorter output and can wait longer.
- Click Generate, then copy the generated Malbolge program.
- Switch to the interpreter tab, paste the program, and click Execute.
The generator types have different tradeoffs. The linear generator emits code quickly and is good for long strings. The branch-on-read generator searches recursively and can produce shorter programs, though generation time grows quickly. The fixed-length generator can find the shortest program among the modes, but it is the slowest and most practical choice only for short strings. The source code is available at zb3/malbolge-tools.
For a simple paste-and-run workflow, Try It Online also has a Malbolge interpreter. Select Malbolge, paste the source, and press Run.
Option 2: generate from a terminal
wallstop/malbolge-toolkit provides a Python generator, interpreter, command-line interface, and beginner primer.
git clone https://github.com/wallstop/malbolge-toolkit.git
cd malbolge-toolkit
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e .
Generate a program that prints text:
python -m malbolge.cli generate --text "Hello from Malbolge" --seed 42
The command prints the internal opcode sequence, the raw ASCII Malbolge program, the expected machine output, and search statistics. Use the ASCII line as the program source. To save and run a generated program with the Python API:
from pathlib import Path
from malbolge import ProgramGenerator
result = ProgramGenerator().generate_for_string("Hello from Malbolge")
Path("hello.mb").write_text(result.malbolge_program)
print(result.machine_output)
python -m malbolge.cli run --ascii-file hello.mb
Ugly source is normal for the output format. It does not mean the generator failed.
Option 3: assemble a real Malbolge program
Text generators are convenient for demonstrations, but they are not general-purpose compilers. If you need to control registers, memory locations, jumps, and self-modification directly, use an assembler.
LMAO translates a readable assembly language called HeLL into standard Malbolge. It requires gcc, flex, bison, and make.
git clone https://github.com/esoteric-programmer/LMAO.git
cd LMAO
make
./lmao -o hello.mb example_simple_hello_world.hell
HeLL is still low-level: you manage instructions and memory cells manually. It is better understood as an assembler for the Malbolge VM than as a friendly high-level compiler. The repository contains complete HeLL examples, including a cat program that halts at end-of-file.
For a browser-based HeLL workflow, open the HeLL Web IDE, paste a HeLL program, click Assemble, and then click Run. The Malbolge.org toolbox also collects an online debugger, assembler, disassembler, ternary calculator, and example programs.
A small tool map
| Resource | Best for |
|---|---|
| zb3/malbolge-tools | Browser-based generation and execution |
| wallstop/malbolge-toolkit | Python API, CLI generation, interpreter, and primer |
| LMAO and HeLL | Assembling low-level programs into Malbolge |
| Malbolge.org | Reference programs, debugger, assembler, and ternary tools |
| nstarke/malbolge-examples | A collection of classic Malbolge programs |
| Esolang: Malbolge | Concise language specification and technical links |
| Programming in Malbolge | Techniques for writing programs instead of generating them |
| Lou Scheffer’s Malbolge pages | Original specification and cryptanalysis |
When comparing tools, check which dialect they target. Most beginning examples run on ordinary Malbolge. Projects involving Malbolge Unshackled may rely on a larger address space or slightly different input/output behavior and should not be assumed to work with the standard interpreter.
Malbolge in a Neuro-sama ARG
Malbolge has also appeared in alternate-reality games, where an intentionally opaque format is useful as a puzzle layer. One well-documented case is the Neuro-sama ARG video titled [Filtered], released around Halloween 2023.
The community reconstruction of the puzzle is roughly this:
- Morse-code tones at the start of the ARG stream revealed a YouTube video ID.
- Unicode code points in the video’s hidden title decoded to text, and subtracting 784 from their decimal values produced a Malbolge fragment.
- Running that fragment printed
hello wobefore the incomplete program reached an invalid instruction. That was the clue to reconstruct a complete “hello world” program. - The recovered program’s useful instruction sequence then contributed key material used to decrypt another layer of the puzzle.
The recovered fragment preserved by the Neuro ARG Database is:
D'`$q]!n<Z:9VU0vAucrq/o-9+[k(EhVf#z@?>O{)Lrwvotm3qjoh.ONjiha'&dFb[`YX|\>=YXWPOsMRKJINMFjJIHA@d'CB
The fragment is useful because it came from the original puzzle rather than being written as a demonstration. The strange text is executable: running it under the right VM produces part of the next answer.
Malbolge is an obfuscation and puzzle layer rather than an encryption algorithm. It would not automatically make a program a secure way to hide a message. The surrounding key and encryption process protected the ARG’s final message.
The 2024 follow-up video Numbers III is part of the same broad storyline, but its prominent visible puzzle was a 6-by-6 character grid manipulated by row and column rotations. The Malbolge step was in the earlier [Filtered] video. If you want to follow the full chronology, the ARG database and the community lore explainer are good places to continue.
Why it is still interesting
Malbolge hides a lot of behavior inside a small machine. It combines an unfamiliar number system, a non-obvious decoding table, self-modifying instructions, and address-dependent encoding. Reverse engineering it means separating the current bytes, the decoded operation, the register state, and the history that produced them.
It remains a popular esoteric-programming benchmark because these layers make generation, analysis, and translation separate challenges. Generating a working program is a search problem; reading one requires virtual-machine analysis; and translating one requires understanding exactly what the machine model permits.
The language is more interesting as a design exercise than as a practical tool. It shows how a language designer can turn every obvious convenience into an obstacle.
The etymology and general history are summarized by Wikipedia and Esolang. ↩︎
Andrew Cooke generated the first known “Hello, world!” program by search; Lou Scheffer later documented instruction cycles and cryptanalysis. See Cooke’s archived write-up and Scheffer’s Malbolge pages. ↩︎
See Malbolge Unshackled and the bounded-storage discussion. ↩︎
The interpreter and initialization rules follow Ben Olmstead’s reference implementation and specification. ↩︎
- (Published)
- (Modified)
Some information might changes over time, we keep redaction up to date.