Introduction to Malbolge



Counter

Although the language had been out since 1998, for many years the most complex known programs was 'hello, world', available in several versions.

http://www.acooke.org/andrew/writing/malbolge.html

http://www.antwon.com/index.php?p=234

http://www.wikipedia.org/wiki/Malbolge_programming_language

http://www2.latech.edu/~acm/helloworld/malbolge.html



In 2004, based on the analysis below, I wrote a program that copied input to output, though it did not terminate properly on end of input.



There was a claim that the '99 bottles of beer' program had been written in Malbolge. ( The site was (now dead): http://99-bottles-of-beer.ls-la.net/m.html) The implication is that the program was doing looping, testing and printing. However, closer examination shows that the programmer was just doing a printf("") of the desired result using straight line code. Conceptually this is exactly the same as the 'hello world' example above.



This difficult task of writing a general program in Malbolge was completed for real in 2005 by Hisashi Iizawa , Toshiki Sakabe, Masahiko Sakai , Keiichirou Kusakari, and Naoki Nishida. Their paper "Programming Method in Obfuscated Language Malbolge" (in Japanese) can be found at http://www.sakabe.i.is.nagoya-u.ac.jp/~nishida/DB/pdf/iizawa05ss2005-22.pdf. The resulting source code for '99 bottles of beer' can be found at: http://www.99-bottles-of-beer.net/language-malbolge-995.html . Though some of the theory developed here was used, reducing this to practice was an amazing feat of programming prowess.

Malbolge as a cryptosystem

Looked at as a cryptosystem, it has several weaknesses:



Some permutation cycles are short

Jump instructions do not self modify



Instruction at C is executed Instruction at C is scrambled by the permutation table C is incremented

Initializing values





begin 666 copy.mb

M1"="04 _/CT\.SHY.#<V-30S,C$P+RXM+"LJ*2@G)B4D(R(A?GU\>WIY>'=V

M=71S<G%P;VYM;&MJ:6AG9F5D8V)A8%]>75Q;6EE85U955%-245!/3DU,2TI)

M2$=&141#0D% /SX]/#LZ.3@W-C4T,S(Q,"\N+2PK*BDH)R8E)",B(7Y]?'MZ

M>7AW=G5T<W)Q<&]N;6QK:FEH9V9E9&-B86!?7EU<6UI96%=655134E%03TY-

M3$M*24A'1D5$0R9?O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]

MO;V]Y+V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]

MO;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]

MO;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]

MO;V]O>2]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]

DO;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;V]O;T*



end





Here are some more observations, not taken advantage of yet:

Getting aroung the effect of self modifying instructions

Input OP rotate

Input (at location 53, mod 94)

Branch to 82 OP (at location 82, mod 94)

branch to 59

rotate (at location 59, mod 94)

branch

Building immutable NOPs

Some observations on the OP operator:



| A trit:

________|_0__1__2_

0 | 1 0 0

*D 1 | 1 0 2

trit 2 | 2 2 1

Loads and Stores:



Doing arithmetic in Malbolge

Code Density

A general strategy for writing larger Malbolge programs, and proving practical Turing completeness.

Proving formal Turing completeness.

It could be worse



Redo the instruction permutation table to remove all short cycles.

In particular, if every possible cycle for every location contains at least one non-NOP instruction, then you could not even construct a NOP that you could rely on.



Remove the oversight in the reference interpreter that lets the user load non-ascii values directly.

You could make the OP even less useful by modifying it so that as few rows and columns as possible contain all three digit values. This makes it hard to set specific values that contain all three trits. Alternatively, make OP so that as many rows and columns as possible contain all three trit values. This makes it very hard to set a memory address to anything unless you know the prior value.

Modify instructions as they are fetched, not when they are done. Then branches too would self modify.







From Ryan Kusnery's weird languages page:



