Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

life gets obfuscated

by IraTarball (Monk)
on Nov 28, 2001 at 23:55 UTC ( #128156=obfuscated: print w/replies, xml ) Need Help??

Hello Monks,
This is my first attempt at (deliberate) obfuscation. It's a version of John Conway's Game of Life.

For those unfamiliar with the game, the rules are simple.
You define a grid and initialize each cell to either living or dead.
Then you traverse the grid checkin the surrounding cells.
If the current cell is alive it stays alive as long as 2 or 3 of its neighboring cells are alive.
If the current cell is dead it can come to life if exactly 3 neighbors are alive.

This code can take an argument to define the grid size, 20 seemed like a good size for my terminal window.

map{sub __;$/=$_;sub _;map{$g[$/][$_]{c}=rand(time)%2;push@{$g[$/][$_] +{n}}, ( \$g[_$/][ $_]{c} =>\$g[__$/][ $_]{c}=>\$g[ $/][_$_]{c}=>\$g[ $/][__ +$_]{c}, \$g[_$/][_$_]{c} =>\$g[_ $/][__$_]{c}=>\$g[__$/][_$_]{c}=>\$g[__$/][__ +$_]{c}, )}(0..$s)}(0..($s=(shift or 15)-1));sub __{(($m=shift)+1)<=$s?$m+1:0} +sub _ { (($m=shift)-1)>=0?$m-1:$s}__;__;while(1){map{$/=$_;map{print$g[$/][$_] +{c}; $u +=$$_ for(@{$g[$/][$_]{n}});$t[$/][$_]{c}=$g[$/][$_]{c};$t[ $/][$_]{c} +=($u==3 ?1:($u !=2?0:($t[$/][$_]{c}==1?1:0)));__;$u=~s _.__;}(0..$s);print"\n" +;}(0 .. $s);print"\n";map{$/=$_; map{$g[$/][$_]{c}=$t[$/][$_]{c}}(0..$s)}(0..$ +s);_;_; __;_;__;_;__;_;__;_;sleep 1}__;_;__;_;_;__;_;__;_;_;__;_;__;_;_;__;_;_ +_;_;__;
A few notes on the code...
As I mentioned before, I haven't done any deliberatly obfuscated code before,so this was an interesting experiment for me. I'm actually not too happy with it, to be honest. It mostly is just using all those poor programming practices I normally tell people not to do. I had hoped to do something really clever but alas, this is all I could come up with. Compared to some of the other nodes in this section it's not really even obfuscated.
I'm interested in what other monks might think of it, and would love some suggestions.

Thanks,
Ira,

"So... What do all these little arrows mean?"
~unknown

Replies are listed 'Best First'.
Re: life gets obfuscated
by belg4mit (Prior) on Nov 29, 2001 at 05:39 UTC
    Not any major changes but it seems a bit nicer looking on the eyes and in a terminal.
    map{sub __;$/=$_;sub _;map{$g[$/][$_]{c}=rand(time)%2;push@{$g[$/][$_ +]{n}}, ( \$g[_$/][ $_]{c} =>\$g[__$/][ $_]{c}=>\$g[ $/][_$_]{c}=>\$g[ $/][_ +_$_]{c}, \$g[_$/][_$_]{c} =>\$g[_ $/][__$_]{c}=>\$g[__$/][_$_]{c}=>\$g[__$/][_ +_$_]{c}, )}(0..$s)}(0..($s=(shift or 23)-1));sub __{(($m=shift)+1)<=$s?$m+1:0} + sub _ { (($m=shift)-1)>=0?$m-1:$s}__;__;while(1){map{$/=$_;map{print$g[$/][$_ +]{c}?'*': '.'; $u+=$$_ for(@{$g[$/][$_]{n}});$t[$/][$_]{c}=$g[$/][$_]{c};$t[ $/ +][$_]{c} =($u==3?1:($u !=2?0:($t[$/][$_]{c}==1?1:0)));__;$u=~s _.__;}(0..$s);p +rint"\n"; }(0 .. $s);map{$/=$_; map{$g[$/][$_]{c}=$t[$/][$_]{c}}(0..$s)}(0..$s) +;_;_; __;_;__;_;__;_;__;_;sleep 1}__;_;__;_;_;__;_;__;_;_;__;_;__;_;_;__;_; +__;_;__;

    --
    perl -p -e "s/(?:\w);([st])/'\$1/mg"

life gets (?:more) obfuscated
by belg4mit (Prior) on Nov 30, 2001 at 02:11 UTC
    Not sure if this is much better, at least to me it is much more line-noise and harder to parse.
    map{sub __;$/=$_;sub _;map{$_[$/][$_]{_}=rand(time)%2;push@{$_[$/][$_] +{map}},( \$_[_$/][$_]{_}=>\$_[__$/][$_]{_}=>\$_[$/][_$_]{_}=>\$_[$/][__$_]{_},\ +$_[_$/][ _$_]{_}=>\$_[_$/][__$_]{_}=>\$_[__$/][_$_]{_}=>\$_[__$/][__$_]{_},)}(0 +..$__)}( 0..($__=(shift||24)-1));sub __{(($-=shift)+1)<=$__?$-+1:0}sub _{(($-=s +hift)-1) >=0?$--1:$__;}__;__;while(){map{$/=$_;$\="\n";print map{$_[$/][$_]{sub +}=$_[$/] [$_]{_}?'*':'.';$.+=$$_ for(@{$_[$/][$_]{map}});$![$/][$_]{_}=$_[$/][$ +_]{_};$! [$/][$_]{_}=($.==3?1:($.!=2?0:($![$/][$_]{_}==1?1:0)));__;$.=~s _.__;$ +_[$/][$_ ]{sub};}(0..$__);}(0 .. $__);map{$/=$_;map{$_[$/][$_]{_}=$![$/][$_]{_} +}(0..$__ )}(0..$__);_;for(1..4){_;__;}_;sleep 1;}for(1..3){__;_;__;_;_;}__;_;__ +;_;__;

    --
    perl -p -e "s/(?:\w);([st])/'\$1/mg"

Re: life gets obfuscated
by c0d34w4y (Acolyte) on Dec 11, 2001 at 04:18 UTC
    Yeah... looks pretty cool actually. It's my first attempt at playing with obfuscated perl code.. here's a few changes that I made to the (modified) original:

    $t=pack("cccc",0x74,0x69,0x6d,0x65);map{sub __;$/=$_;sub _;map{$_[$/][ +$_]{_}=rand(eval($t))%2;push@{$_[$/][$_]{map}},(\$_[_$/][$_]{_}=>\$_[ +__$/][$_]{_}=>\$_[$/][_$_]{_}=>\$_[$\/][__$_]{_},\$_[_$/][_$_]{_}=>\$ +_[_$/][__$_]{_}=>\$_[__$/][_$_]{_}=>\$_[__$/][__$_]{_},)}(0..$__)}(0. +.($__=(shift||24)-1));sub __{(++($-=$_[$@]))<=$__?++$-:0}sub _{(--($- +=$_[$\@]))>=0?$--1:$__;}__;__;while(){map{$/=$_;$\="\n";print map{$_[ +$/][$_]{sub}=$_[$/][$_]{_}?'*':'.';$.+=$$_ for(@{$_[$/][$_]{map}});$! +[$/][$_]{_}=$_[$/][$_]{_};$![$/][$_]{_}=($.\==3?1:($.!=2?0:($![$/][$_ +]{_}==1?1:0)));__;$.=~s _.__;$_[$/][$_]{sub};}(0..$__);}(0 .. $__);ma +p{$/=$_;map{$_[$/][$_]{_}=$![$/][$_]{_}}(0..$__)}(0..$__); _;for(1..4){_;__;}_;sle\ep 1;}for(1..3){__;_;__;_;_;}__;_;__;_;__;


    i modified the two subs a bit to make them even more so appealing. Also, i've removed the obvious 'time' method name and replaced it with a packed version of it that is than being evaluated in the map method (aka. loop). I still don't understand some parts of the code rofl. print join(" ", map { sprintf "%#02x", $_ }unpack("C*",pack("L",0x12345678)))
      I know this gets more wicked and sinful with every new post but I found this altered piece of the above obfuscated code rather amusing:
      @c=split/\s/,<DATA>;$c=pack("C".scalar(@c),@c);eval$c; __DATA__ 36 116 61 112 97 99 107 40 34 99 99 99 99 34 44 48 120 55 52 44 48 120 + 54 57 44 48 120 54 100 44 48 120 54 53 41 59 109 97 112 123 115 117 +98 32 95 95 59 36 47 61 36 95 59 115 117 98 32 95 59 109 97 112 123 3 +6 95 91 36 47 93 91 36 95 93 123 95 125 61 114 97 110 100 40 101 118 +97 108 40 36 116 41 41 37 50 59 112 117 115 104 64 123 36 95 91 36 47 + 93 91 36 95 93 123 109 97 112 125 125 44 40 92 36 95 91 95 36 47 93 +91 36 95 93 123 95 125 61 62 92 36 95 91 95 95 36 47 93 91 36 95 93 1 +23 95 125 61 62 92 36 95 91 36 47 93 91 95 36 95 93 123 95 125 61 62 +92 36 95 91 36 47 93 91 95 95 36 95 93 123 95 125 44 92 36 95 91 95 3 +6 47 93 91 95 36 95 93 123 95 125 61 62 92 36 95 91 95 36 47 93 91 95 + 95 36 95 93 123 95 125 61 62 92 36 95 91 95 95 36 47 93 91 95 36 95 +93 123 95 125 61 62 92 36 95 91 95 95 36 47 93 91 95 95 36 95 93 123 +95 125 44 41 125 40 48 46 46 36 95 95 41 125 40 48 46 46 40 36 95 95 +61 40 115 104 105 102 116 124 124 50 52 41 45 49 41 41 59 115 117 98 +32 95 95 123 40 43 43 40 36 45 61 36 95 91 36 64 93 41 41 60 61 36 95 + 95 63 43 43 36 45 58 48 125 115 117 98 32 95 123 40 45 45 40 36 45 6 +1 36 95 91 36 64 93 41 41 62 61 48 63 36 45 45 49 58 36 95 95 59 125 +95 95 59 95 95 59 119 104 105 108 101 40 41 123 109 97 112 123 36 47 +61 36 95 59 36 92 61 34 92 110 34 59 112 114 105 110 116 32 109 97 11 +2 123 36 95 91 36 47 93 91 36 95 93 123 115 117 98 125 61 36 95 91 36 + 47 93 91 36 95 93 123 95 125 63 39 42 39 58 39 46 39 59 36 46 43 61 +36 36 95 32 102 111 114 40 64 123 36 95 91 36 47 93 91 36 95 93 123 1 +09 97 112 125 125 41 59 36 33 91 36 47 93 91 36 95 93 123 95 125 61 3 +6 95 91 36 47 93 91 36 95 93 123 95 125 59 36 33 91 36 47 93 91 36 95 + 93 123 95 125 61 40 36 46 61 61 51 63 49 58 40 36 46 33 61 50 63 48 +58 40 36 33 91 36 47 93 91 36 95 93 123 95 125 61 61 49 63 49 58 48 4 +1 41 41 59 95 95 59 36 46 61 126 115 32 95 46 95 95 59 36 95 91 36 47 + 93 91 36 95 93 123 115 117 98 125 59 125 40 48 46 46 36 95 95 41 59 +125 40 48 32 46 46 32 36 95 95 41 59 109 97 112 123 36 47 61 36 95 59 + 109 97 112 123 36 95 91 36 47 93 91 36 95 93 123 95 125 61 36 33 91 +36 47 93 91 36 95 93 123 95 125 125 40 48 46 46 36 95 95 41 125 40 48 + 46 46 36 95 95 41 59 95 59 102 111 114 40 49 46 46 52 41 123 95 59 9 +5 95 59 125 95 59 115 108 101 101 112 32 49 59 125 102 111 114 40 49 +46 46 51 41 123 95 95 59 95 59 95 95 59 95 59 95 59 125 95 95 59 95 5 +9 95 95 59 95 59 95 95 59 10


      --
      print join(" ", map { sprintf "%#02x", $_ }unpack("C*",pack("L",0x1234 +5678)))

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://128156]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2019-05-22 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (138 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!