Malbolge is
machine language for a
ternary virtual machine, the Malbolge
interpreter. The standard interpreter and the official specification do not match perfectly. One difference is that the compiler stops execution with data outside the 33–126 range. Although this was initially considered a bug in the compiler, Ben Olmstead stated that it was intended and there was in fact "a bug in the specification".
d is the data pointer. It is automatically incremented after each instruction, but the location it points to is used for the data manipulation commands.
Pointer notation d can hold a memory address;
[d] is
register indirect; the value stored at that address.
[c] is similar.
Memory The virtual machine has 59,049 (310)
memory locations that can each hold a ten-trit
ternary number. Each memory location has an address from 0 to 59048 and can hold a value from 0 to 59048. Incrementing past this limit wraps back to zero. The language uses
the same memory space for both data and instructions. This was influenced by how hardware such as x86 architecture worked. In 2007, Ørjan Johansen created Malbolge Unshackled, a version of Malbolge which does not have the arbitrary memory limit. The hope was to create a Turing-complete language while keeping as much in the spirit of Malbolge as possible. No other rules are changed, and all Malbolge programs that do not reach the memory limit are still completely functional.
Instructions Malbolge has eight
instructions. Malbolge figures out which instruction to execute by taking the value
[c], adding the value of
c to it, and taking the remainder when this is divided by 94. The final result tells the interpreter what to do: After each instruction is executed, it gets encrypted (see below) so that it will not do the same thing next time, unless a jump just happened. Right after a jump, Malbolge will encrypt the instruction just prior to the one it jumped to instead. Then, the values of both
c and
d are increased by one and the next instruction is executed.
Crazy operation For each ternary digit of both inputs, use the following table to get a ternary digit of the result. For example,
crz 0001112220, 0120120120 gives 1120020211.
Encipherment After an instruction is executed, the value at
[c] (without anything added to it) will be replaced with itself
mod 94. Then, the result is
enciphered with one of the following two equivalent
methods. ; Method 1: Find the result below. Store the ASCII code of the character below it at
[c]. 0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123 ---------------------------------------------------------------------------------------------- 9mU!pJS72FhOA1CB6v^=I_0/8|jsb ; Method 2: Find the result below. Store the encrypted version at
[c]. Lou Scheffer's cryptanalysis of Malbolge mentions six different cycles in the
permutation. They are listed here: • 33 ⇒ 53 ⇒ 45 ⇒ 119 ⇒ 78 ⇒ 49 ⇒ 87 ⇒ 48 ⇒ 123 ⇒ 71 ⇒ 83 ⇒ 94 ⇒ 57 ⇒ 91 ⇒ 106 ⇒ 77 ⇒ 65 ⇒ 59 ⇒ 92 ⇒ 115 ⇒ 82 ⇒ 118 ⇒ 107 ⇒ 75 ⇒ 104 ⇒ 89 ⇒ 56 ⇒ 44 ⇒ 40 ⇒ 121 ⇒ 35 ⇒ 93 ⇒ 98 ⇒ 84 ⇒ 61 ⇒ 100 ⇒ 97 ⇒ 46 ⇒ 101 ⇒ 99 ⇒ 86 ⇒ 95 ⇒ 109 ⇒ 88 ⇒ 47 ⇒ 52 ⇒ 72 ⇒ 55 ⇒ 110 ⇒ 126 ⇒ 64 ⇒ 81 ⇒ 54 ⇒ 90 ⇒ 124 ⇒ 34 ⇒ 122 ⇒ 63 ⇒ 43 ⇒ 36 ⇒ 38 ⇒ 113 ⇒ 108 ⇒ 39 ⇒ 116 ⇒ 69 ⇒ 112 ⇒ 68 ⇒ 33 ... • 37 ⇒ 103 ⇒ 117 ⇒ 111 ⇒ 120 ⇒ 58 ⇒ 37 ... • 41 ⇒ 102 ⇒ 96 ⇒ 60 ⇒ 51 ⇒ 41 ... • 42 ⇒ 114 ⇒ 125 ⇒ 105 ⇒ 42 ... • 50 ⇒ 80 ⇒ 66 ⇒ 62 ⇒ 76 ⇒ 79 ⇒ 67 ⇒ 85 ⇒ 73 ⇒ 50 ... • 70 ⇒ 74 ⇒ 70 ... These cycles can be used to create loops that do different things each time and that eventually become repetitive. Lou Scheffer used this idea to create a Malbolge program (included in his cryptanalysis linked below) that repeats anything the user inputs. == Variants ==