December 5, 2006

Negaposi - The language made up of just + and -
Post by Peter Cooper

Following on from yesterday's post about Ruby obfuscation comes one of the better known entries to the obfuscation contest, Negaposi.

Negaposi is a small Ruby class that implements a language that's made up of only + and - symbols.

Here's an example Negaposi 'program':

+-+--++----+--+-+++--+-------+--++--+++---+-+++-+-+-+++-----+++-_
+--++++--+---++-+-+-+++--+--+-+------+--++++-++---++-++---++-++-_
+++--++-+-+--++--+++--+------+----+--++--+++-++-+----++------+--_
-+-+----+++--+--+----+--+--+-++-++--+++-++++-++-----+-+-+----++-_
---------+-+----

Rather more practically, however, here's how Negaposi is implemented:

def  initialize a=@p=[], b=@b=[];                      end
def +@;@b<<1;b2c end;def-@;@b<<0;b2c                   end
def  b2c;if @b.size==8;c=0;@b.each{|b|c<<=1;c|=b};send(
     'lave'.reverse,(@p.join))if c==0;@p<<c.chr;@b=[]  end
     self end end ; begin _ = NP.new                   end

Florian Groß has put together a guide explaining how Negaposi works. If explanations of obfuscated programs interests you, Florian has more for you.

Creator, Sasada Koichi, however, laments that he didn't win a prize, but has put together a Negaposi 'compiler'.