Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Cooking with Perl

by zdog (Priest)
on Dec 25, 2000 at 04:23 UTC ( #48215=obfuscated: print w/replies, xml ) Need Help??

#!/usr/bin/perl -w # cooking with perl use strict; {$_.=<DATA>;redo if !eof(DATA); }s/[ \n3A-Z]//g;s /000/032/g; my @z = split //; for (my $i=0;$i<24; $i++) { $_[@_] = "$z[@_*3]$z[@_*3+1]$z[@_*3+2]" } my $z; map $z .= chr($_),@_; $_ = $z."\n"; print; __END__ 303 X373X343 X313 X313X373X31 3X313X353X313X313X3 63X303X303X 303X3 03X393X373X3 13X3 1 3X 303X313X3 1 3X31 3X 313X313X36 3X31 3X303X343 X313X303X313X313X313X343X303X303X303 X303X383X303X313X303X313X313X313X343X 313X303X383X303X303X303X303X373X323X30 3X393X373X303X393X393X313X303X373X313X3 03X313X313X313X343X33X33X33X33X33X3 3X33X33X33X33X33X33X33X33X33X33X X33X33X33X33X33X33X33X33X33X33 X33X33X33X33X33X 33X33X33X3 3X33X3 3X33X33X33 X33X 33X 33X33 X33 X33 X33X 33 X3 3X 33 X3 3X 33 X3 3X 33 X3 3X 33X 33X 33

Zenon Zabinski | zdog |

Replies are listed 'Best First'.
Re: Cooking with Perl explained by Iron Chef Macphisto
by Macphisto (Hermit) on Jan 05, 2001 at 00:05 UTC
    Okay, Being that I talk to zdog and really respect his level of programming skill, I decided I'd explain how this one went because while it's somewhat simple, zdog was very creative with it and I like it more than most.

    First we'll make it look more recognizable and throw in some quick commentary
    #!/usr/bin/perl -w # cooking with perl -- "mmm I hope it's +pie" use strict; { $_.=<DATA>; # read one line of <DATA> redo if !eof(DATA); # read all of data into $_ } s/[ \n3A-Z]//g; # delete any newline, any digit '3'and any A- +Z s/000/032/g; # switch any 000 with a 032 my @z = split //; # Puts $_ into the array @z for (my $i=0;$i<24;$i++) # 23 loops { $_[@_] = "$z[@_*3]$z[@_*3+1]$z[@_*3+2]" # Chops $_ into three digit + sections } my $z; map $z .= chr($_),@_; # maps each three digit sequence into chr($_) to + create each letter in the japh $_ = $z."\n"; #Throws a new line to the end of the $z and stores it in +to $_ print; # prints $_

    Now for a line by line description:
    Line 1-2 These are of course self explanatory
    Line 3-6 This little construct will read all of <DATA> into $_ ending when DATA ends of course
    Line 7 The regex here takes out all of the newlines, all the digits'3' and all any alpha numeric ( capital of course ). Which leaves us with the following string07411711511603209711011101161041011140320801011141000072097099107101114 ( hope I didn't miss any )
    Line 8 Switches all 000's in the above string with 032
    Line 9 Throw $_ into the array @z
    Line 10-13 This for loops mercilessly hacks the digit string into sections of three digits. Giving us the following:
    074 117 115 116 032 097 110 111 116 104 101 114 032 080 101 114 100 007 209 709 910 710 111 4
    Line 14 Declares $z
    Line 15 maps the character representation of each three digit piece into $z
    Line 16 Adds a new line to $z and assigns it to $_
    Line 17 Prints $_ and thus prints "Just Another Perl Hacker"

    I was very impressed with this and hope my explination was adequate.

    Iron Chef Macphisto
    Next episode I'll show you how to make Perl Pie
    Addendum: zdog noted that I had mistyped and said the for loop iterates 23 times when it really iterates 24 times. I was typing too fast.

    Everyone has their demons....

      Thanks for the explanation, since then it was just easy to follow the code. ++votes for you and for zdog.

      One more thing. As I got 'another' in lowercase (guess you made a typo in the explanation), and curious enough, I wondered what changes to introduce in the data to get a capital A. So I replaced the meaningless '3' and 'X' chars with hiphens, just to track down the '097' ASCII code. As it can be easily seen:

          -0-    --7---4-
          --1-  --1---7---1
          6---0---0--   -0---
         0---9---7---    1---
       1 -- -0---1---  1 ---1
        --  -1---1---6  ---1
                      ---------------- ----------
                       ------           ----------
                        ----            ---   -----
                         ---              ---    ----
                          --               --      --
                          --               --      --
                          --              --       --
                          --             --        --
                        ---            ---        --

      it is in line 5. Replaced it with '065' and I was done.

      Where is the promissed Perl pie? :-)

      -- Ricardo
      use MacPerl;
Re: Cooking with Perl
by ZX (Novice) on Dec 30, 2000 at 03:19 UTC
    I think this a very unusual node, but I like it!
Re: Cooking with Perl
by OzzyOsbourne (Chaplain) on Dec 28, 2000 at 22:07 UTC

    I usually do not comment on obfuscation, nor try to decode it, but this took me a while to manually figure out what it did.

    I am very impressed. I have but one ++ to give.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://48215]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2018-06-25 13:03 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.