Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

The Matrix Reloaded: JAPH

by davido (Archbishop)
on Sep 01, 2003 at 22:14 UTC ( #288199=obfuscated: print w/ replies, xml ) Need Help??

The Matrix has now been reloaded with Perl hackers.

This JAPH is set to work best on screens of 70 columns or more. If you have fewer than 70 cols., I left the adjustment easy to find.

This JAPH has tested successfully on Unix, Linux, and Win98.

Once you see what it does, walking through it probably won't be too awfully tricky, but post any comments or suggestions so that I can learn something too. Let me know what you think!

Here's the code. Prepare yourself to enter the Matrix.

map{my$qw;map{!$q[$_]&&rand>.993?do{$q[$_]=${[qw$Just another Perl hacker$]}[$qq++].q$.$x5 .q$ $x5;$qq=$qq>3?0:$qq}:0;$q[$_]?do{($qx, $q[$_])=split//,$q[$_],2;$qw.=$qx}:{$qw.=q$ $}}1..70;;print$qw,$/; select$a,$a,$a,.06}1..300

Enjoy!!!

Dave

"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Comment on The Matrix Reloaded: JAPH
Download Code
Re: The Matrix Reloaded: JAPH
by Anonymous Monk on Sep 01, 2003 at 23:13 UTC

    Some free advice:

    • If you put your code in a long line that doesn't fit in an editor's screen you are just going to annoy people, so if you were thinking of amazing everyone with your cunning technique, think again.
    • An obfuscation is like a joke, and as such the way you tell it is more important than its contents. If you explain a joke, you spoil it. So the readers, rather than looking at your in amazement for you explanation, are just going to get annoyed (again).
    • Spend some time looking at the good examples of obfuscation in the Monastery. Look at Erudil, BooK, Abigail, but there are many others. Once you know how to "read" an obfuscation, you should attempt writing a good one.

    HTH

    Edit: Closed <ul> correctly. larsen

      The JAPH was put into one line initially because it is intended to be used as a one liner. As a one liner, it can be run as perl -e '....', or it can be plopped into an editor where anyone may prepend a #!/usr/bin/perl line.

      But for those with long-line-challenged editors (I was unaware that some editors were incapable of dealing with long lines), I've now cut it down into separate lines. Being presented as a one-liner had nothing to do with its obfuscation, so I'm not quite clear on how the one-line presentation might have made you think I was trying to wow the world with cunning technique. This site provides an easy way to download the code regardless of its number of lines.

      I've looked at many examples, and many do wow me. I'm not to that level yet, but still enjoy plinking around here and there, and thought that this one was fun.

      Apparently you also have spent some time viewing JAPH's from other members of the forum, and obviously you've been around the local block, which leads me to ask why did you post anonymously?

      HTH.

      Dave

      "If I had my life to do over again, I'd be a plumber." -- Albert Einstein

      If you put your code in a long line that doesn't fit in an editor's screen you are just going to annoy people

      We are not annoyed. The only time I get annoyed is when the "download code" link displays something unusable. I can't even recall the last time I ran into this, despite my giving most japhs and obfu a try.

      An obfuscation is like a joke, and as such the way you tell it is more important than its contents. If you explain a joke, you spoil it. So the readers, rather than looking at your in amazement for you explanation, are just going to get annoyed (again).

      I suspect most others do not share your opinion. I certainly don't mind reading about someone's thought process, inspirations, comments, or even credits regarding their work.

      Spend some time looking at the good examples of obfuscation in the Monastery. Look at Erudil, BooK, Abigail, but there are many others. Once you know how to "read" an obfuscation, you should attempt writing a good one.

      I certainly admire people who take a crack at writing an obfu. I hope people who are not as good at it as the aforementioned will ignore this ridiculous statement by Anonymous Coward^H^H^H^H^H^HMonk and continue to post. Not everyone is as good at it as some some of our more esteemed brethren, but fortunately it is actually rare that someone is told or implied that their post is unworthy. Also fortunate is that posters often receive constructive criticism and are able to expand their understanding of obfu and create something of increased skill.

      --
      "I just read perlman:perlboot," said Tom, objectively.
      naChoZ

Re: The Matrix Reloaded: JAPH
by 914 (Pilgrim) on Sep 01, 2003 at 23:38 UTC
    works peachy with ActiveState 5.8 over WinXP...

    cheers! ;-)

Re: The Matrix Reloaded: JAPH
by mildside (Friar) on Sep 02, 2003 at 05:35 UTC
    I liked it - worked well under Cygwin.

    Cheers!

Re: The Matrix Reloaded: JAPH
by blackstarr (Pilgrim) on Sep 02, 2003 at 06:28 UTC
    Unlike AnonyMonk, I actually like this.

    Worked perfectly on my Win2K box with Activestate 5.8.0!

    Wonder if anyone could figure out a way for the text to descend the screen, as with the "real" Matrix? Is there a technique someone could point me to, or is it only possible in a graphical client?

    So Long
    blackstarr

      A possibility is redrawing the whole screen at each frame. For instance (only tested on linux):

      #!/usr/bin/perl -w # Array containing all lines my @screen = ( ' 'x70 . "\n" ) x 20; # Array of possible (equiprobable) characters my @char = split //, ' *|'; while(1) { print join '', @screen; # Drop last line pop @screen; # Put a new line on top unshift @screen, join ( '', map { $char[ rand(@char) ] } (1..70) ) + . "\n"; # Sleep for 0.1 seconds select(undef, undef, undef, 0.1); }

      Update: The value 20 in the @screen initialization should be at least the terminal height minus 1 (due to the last line being empty). If it's less, then the upper portion of each frame is filled by the last lines of the previous one.

      Cheers

      Antonio

      The stupider the astronaut, the easier it is to win the trip to Vega - A. Tucket
        Seems to work nicely under ActiveState Perl 5.8.0 on Windows 2000.


        "Ex libris un peut de tout"

        So, incorporating abell and cfreak's suggestions, you get:

        #!/usr/bin/perl -w @screen = ( ' 'x70 . "\n" ) x 20; $gen_line = sub { my $qw; for(1..70){ if( !$q[$_] && rand > .993 ){ $q[$_] = q$.$ x 5 . q$ $ x 1 . ${ [ qw$tsuJ rehtona lreP rekcaH$ ] }[$qq++] . q$ $ x 1 . q$.$ x 5; $qq = $qq > 3 ? 0: $qq; } if( $q[$_] ){ ( $qx, $q[$_] ) = split//, $q[$_],2; $qw .= $qx; }else{ $qw .= q$ $; } } "\33[0;32m$qw\33[0m"; }; while(1) { print join '', @screen; # Drop last line pop @screen; # Put a new line on top unshift @screen, $gen_line->() . "\n"; # Sleep for 0.1 seconds select(undef, undef, undef, 0.1); }

        Cool, monks! =]


        cp
        ----
        "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
Re: The Matrix Reloaded: JAPH
by zakzebrowski (Curate) on Sep 02, 2003 at 11:23 UTC
    Dude, I was having a crappy day till I read the node and said, hmm. what is all the hubbub about? I must say this is super sweet obfuscation... :) Cheers.

    ----
    Zak
Re: The Matrix Reloaded: JAPH
by nimdokk (Vicar) on Sep 02, 2003 at 12:01 UTC
    Well, that brightened up the start of a potentially crappy day, thanks :-)


    "Ex libris un peut de tout"
Re: The Matrix Reloaded: JAPH
by cfreak (Chaplain) on Sep 02, 2003 at 14:42 UTC

    davido++! very nice. I was working on something like this but never got around to finishing it. Too bad because I knew that someone would do it eventually :)

    Something that you might be able to add: if the terminal supports it you can add the correct escape sequences to get some green color like so:

    # there may be some others but these are the ones I know of if($ENV{TERM} =~ /linux|xterm|xterm-color|vt220|ansi/) { $color = 1; } # assuming $char is the character you are about to print $char = "\33[0;32m$char\33[0m" if $color;

    \33[ is the escape 0;<nn>m is the color (32 is green 30 - 39 seem to be the only ones that work) the \33[0m at the end returns it to the default white.

    Hope you find that interesting :)

    Lobster Aliens Are attacking the world!
      in Windows 2000 you can use the line
      system ("color 0A");
      to turn the color to black background, green foreground.
        You mean black bg and green fg isn't your default color scheme on Win2K?
        :-)

        Believe nothing, no matter where you read it, or who said it - even if I have said it - unless it agrees with your own reason and your own common sense. -- Buddha
        Thanks for the color tip... I was able to sucessfully use it on an old system with a crappy monitor, and people said 'howdya do that?!' :)

        ----
        Zak

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-12-18 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (40 votes), past polls