in reply to Re^2: Output of mindfcuk
in thread Output of mindfcuk

I'm still not able to figure what is happening in the middle part, with so many "while" loops.

You see, the Perl code is simple in that it uses a very limited subset of the language. And it is complex in that it uses lots of construct from that subset to do thing that in "proper" Perl would take a single statement. Thus you may look at it as an obfu demunging exercise, the point being here, that single steps are easily understandable. To grasp the overall picture is purely a matter of having the time and the will to follow them all. (Perhaps running in the debugger could help.) As an example consider the following excerpt, chosen randomly:

while($m[$p]){ $p-=1; $m[$p]+=10; $p+=1; $m[$p]-=1; } $p-=1; $m[$p]+=3; $p+=1; $m[$p]=ord getc; print chr$m[$p];

The first loop repeatedly modifies $p by respectively adding and subtracting one to it, so that in fact it just bounces between two values which are respectively its initial one, say $p, and $p-1. It repeatedly subtracts one to the former until it become zero and adds ten to the latter. Without using a loop that amounts to

$m[$p-1] += 10 * $m[$p]; $m[$p] = 0;

The second assignment is redundant though, because the value is not used later before it gets assigned something completely different. Then ord and chr are inverse functions, so except for the side effect of assigning to $m[$p], the last two statements just amount to

print getc;

And so on...

Replies are listed 'Best First'.
Re^4: Output of mindfcuk
by Anonymous Monk on Jun 10, 2007 at 18:55 UTC

    Thank you, blazar.

    The sad thing (for me) is I went through almost every part of the code and I understand about 90% of what's going on at every interval point (set by me). Yet, I can't seem to have an idea of what username is required by the program. Here's a snippet of my debugging attempt:
    print "\nm1: $m[$p]\n"; $m[$p]+=3; print "p1: $p\n"; print "\nm2: $m[$p]\n"; print "\nAt the beginning2\n"; for $i (0..@m) { print "m${i}: $m[$i]\n"; }
      The sad thing (for me) is I went through almost every part of the code and I understand about 90% of what's going on at every interval point (set by me). Yet, I can't seem to have an idea of what username is required by the program.

      The point is that as I showed you with a randomly picked snippet, translation in more compact, more directly understandable Perl is easy albeit annoying and time consuming. I suppose most of us are plainly not interested in doing so for the whole program although I suggest you do. Perhaps some degree of automated "simplifying" could be possible, but however simple the code is, I would expect that writing a program doing that would take more time and more efforts than proceeding manually. Thus I recommend you to take a step by step approach simplifying the original program gradually into "saner" Perl, making sure at each step that the program is still syntactically correct and for what is possible that it also runs just fine. When you're stuck at a point where you can't go on anymore, then you may have a more interesting Perl question and people may be more willing to help you.

        I understand.

        I was hoping someone here might be able to quickly decipher the program without having to go through every line of it, and point me in the right direction.

        I'll try to have more "print" statements to see if I could find something that might give me a clue.

        Cheers and thanks :)