Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this obfuscated Perl code work?

How does this code work at all?

#!/usr/bin/perl

$i=4;$|=@f=map{("!"x$i++)."K$_^\x{0e}"}
"BQI!\\","BQI\\","BQI","BQ","B","";push
@f,reverse@f[1..5];@f=map{join"",undef,
map{chr(ord()-1)}split""}@f;{;$f=shift@
f;print$f;push@f,$f;select undef,undef,
undef,.25;redo;last;exit;print or die;}
like image 689
user279639 Avatar asked Feb 23 '10 16:02

user279639


1 Answers

Lets first put this through perltidy

$i = 5;
$| = @f = map { ("!" x $i++) . "9$_*\x{0e}" } ">>>E!)", ">>>E)", ">>>E", ">>>", ">>", ">", "";
push @f, reverse @f[ 1..5 ];
@f = map {
    join "",
      map { chr(ord() - 1) }
      split //
} @f;
{
    $f = shift @f;
    print $f;
    push @f, $f;
    select undef, undef, undef, .25;
    redo;
    last;
    exit;
    print or die;
}

The first line is obvious.

The second line makes a list ">>>E!)", ">>>E)", ">>>E", ">>>", ">>", ">", "", and spaces them all to be equally long and appends an asterisk and a 'Shift Out' (the character after a carriage return).

The third line appends items 5 to 1 (in that order) to that list, , so it will be ">>>E!)", ">>>E)", ">>>E", ">>>", ">>", ">", "", ">", ">>", ">>>", ">>>E".

The map decrements the all characters by one, thus creating elements like 8===D ().

The second loop simply prints the elements in the list in a loop every 0.25 seconds. The carriage return causes them to overwrite each other, so that an animation is seen. The last couple of lines are never reached and thus bogus.

like image 104
Leon Timmermans Avatar answered Sep 21 '22 17:09

Leon Timmermans