Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Amazing Regexp Grinder (ARG)

by Dog and Pony (Priest)
on Feb 26, 2002 at 15:14 UTC ( [id://147592]=obfuscated: print w/replies, xml ) Need Help??

Sorry. Couldn't come up with a better name. Heh.

Anyways, I don't much take interest in obfuscations that use a big heap of arbitrary characters and then do a pack or ord on them - although if it forms images, it can be nice. I like obfuscations where it isn't very obvious what really happens, and the trick is to figure that out. Having said that, my new obfu has a long line with arbitrary characters in it. Go figure. But please, go figure it out. I have a hard time judging if this is way too obvious or not. :)

The program takes an optional commandline argument, which should be your name, or defaults to "Dog and Pony". It will then tell you what it thinks.

#!/usr/bin/perl -wl0040 use strict; use English; use vars qw( $ARG ); # Amazing Regexp Grinder (ARG) # Usage: perl arg.pl <your-name> $_ = shift || "Dog and Pony"; print "\n$_:\n"; $ARG = qr( /^C^C^C^P\\\[^D"\[^P^C""0"\0\/""\0""!!0""0\0""0\0""0!!\/"""0"\[^P^C0 +\[!^C^P"\[^C0^P\/\\\0"!"0"!"0\["\\"0""0\/^P^C0"""0"\[\[\\\\0"\0/ ); ($_=~s/$ARG/JAPH/ || s/(\W)/\$$1/g && s/\$(\s)\$//g && s'([^/]+)'#$1\' +) or warn "No match!"; print qq($') && eval;

Hope I brought a few moments amusement, at least. :)

UPDATE: Solution added.


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.

Replies are listed 'Best First'.
Re: Amazing Regexp Grinder (ARG)
by grinder (Bishop) on Feb 26, 2002 at 17:21 UTC
    huh, what, did someone mention my name?

    Nice obfu. That regexp makes me want to gouge out my eyeballs.

    When you say I don't much take interest in obfuscations that use a big heap of arbitrary characters and then do a pack or ord on them you are on the same wavelength as BooK, obfu-meister extraordinaire, who considers such obfus as mere toys.

    This, on the other hand, is evil. Deparsing produces code that doesn't perform the same way. And introducing print statements to see what is going on makes it bomb out with syntax errors. Fierce!


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
SOLUTION: Amazing Regexp Grinder (ARG)
by Dog and Pony (Priest) on Mar 01, 2002 at 01:55 UTC
    It is no fun to write something you think is clever, unless you can show off with all the nitty-gritty. I was really hoping that someone bored enough would attempt to decode this one, but I decided to post a spoiler myself instead. Hopefully, some people will enjoy the "tricks" I tried to employ - almost all of them are misdirections, trying to make you beleive something else is happening. Did it work? Inquiring minds want to know... anyways, thanks for letting me waste some of your time. Keep on making unmaintainable code out there. :)
    #!/usr/bin/perl -wl0040
    
    These switches sets some special variables for me, which I will be using later. It sets $/ to a newline character, and $\ to a space character. See perlrun for details.
    use vars qw( $ARG );
    
    Minor thingy that will not fool many, but I don't like being sloppy, can I avoid it; this has no actual effect, but tries to hide the fact that use English; aliases $_ to $ARG.
    $ARG = qr(
    
      /^C^C^C^P\\\[^D"\[^P^C""0"\0\/""\0""!!0""0\0""0\0""0!!\/""
      "0"\[^P^C0\[!^C^P"\[^C0^P\/\\\0"!"0"!"0\["\\"0""0\/^P^C0"
      ""0"\[\[\\\\0"\0/
    );
    
    Here is a fun part. This looks very much like a hairy regular expression, yes? Well, I am not gonna use it as a such. Actually, I am using qr instead of q - I am gonna use $ARG as a plain string. I also use the slashes at the start and end (marked with blue) to make it look even more like a regular expression - in reality, they would probably break your otherwise valid regexp if you add them. I will get back to this later, though.

    So, what about this match then?

    ($_=~s/$ARG/JAPH/ ||
      s/(\W)/\$$1/g && s/\$(\s)\$//g && s'([^/]+)'#$1\')
        or warn "No match!";	
    
    When you have figured out that $_ and $ARG are the same, you will expect this to match, and the rest of the line to not execute. Also, if you are a bit gullible, you might suspect that the JAPH part has something to do with the final output. But if you use this "regexp" as a string, it will look like this:
     (?-xism:
    
      /^C^C^C^P\\\[^D"\[^P^C""0"\0/""\0""!!0""0\0""0\0""0!!/"""
      0"\[^P^C0\[!^C^P"\[^C0^P/\\\0"!"0"!"0\["\\"0""0/^P^C0"""0
      "\[\[\\\\0"\0/
    
    Which will not match the regexp that it forms, so in reality it could just as well say:
    (0 || s/(\W)/\$$1/g && s/\$(\s)\$//g
      && s'([^/]+)'#$1\') or warn "No match!";	
    
    ($_=~s/$ARG/JAPH/ || s/(\W)/\$$1/g &&
      s/\$(\s)\$//g && s'([^/]+)'#$1\') or warn "No match!";	
    
    This part is straightforward: it simply adds a dollarsign ($) in front of every non-word character, producing:
     $($?$-xism$:$
    $       $
    $ $ $/$^C$^C$^C$^P$\$\$\$[$^D$"$\$[$^P$^C$"$"0$"$\0$/$"$"$\
    0$"$"$!$!0$"$"0$\0$"$"0$\0$"$"0$!$!$/$"$"$"0$"$\$[$^P$^C0$\
    $[$!$^C$^P$"$\$[$^C0$^P$/$\$\$\0$"$!$"0$"$!$"0$\$[$"$\$\$"0
    $"$"0$/$^P$^C0$"$"$"0$"$\$[$\$[$\$\$\$\0$"$\0$/$
    $)
    
    Notice the highlighted part, because next regexp is just there to take that part out, with the newline. No magic. :)
    ($_=~s/$ARG/JAPH/ || s/(\W)/\$$1/g && s/\$(\s)\$//g &&
      s'([^/]+)'#$1\') or warn "No match!";	
    
    ($_=~s/$ARG/JAPH/ || s/(\W)/\$$1/g && print
      && s/\$(\s)\$//g && s'([^/]+)'#$1\') or warn "No match!";	
    
    print qq($') && eval;
    
    The highlighting should explain it - most would expect that I am matching something (actually, everything up till the first forward slash), and then adding a '#' in front of it. And since everything (mostly) seems to close alright, and we even have a warning in case something goes wrong, this should be it. But in reality, I am substituting everything up till said slash with the beginning of the next line too. See the green highlights to see which outer parenthesis actually match too. This makes our $_ look like this at the moment:
     #$1') or warn "No match!";
    
    print qq($/$^C$^C$^C$^P$\$\$\$[$^D$"$\$[$^P$^C$"$"0$"$\0$/$
    "$"$\0$"$"$!$!0$"$"0$\0$"$"0$\0$"$"0$!$!$/$"$"$"0$"$\$[$^P$
    ^C0$\$[$!$^C$^P$"$\$[$^C0$^P$/$\$\$\0$"$!$"0$"$!$"0$\$[$"$\
    $\$"0$"$"0$/$^P$^C0$"$"$"0$"$\$[$\$[$\$\$\$\0$"$\0$/)
    
    Which, when evaled, of course interpolates all these variables. Depending on which variables, they have different defaults (they are perl special vars), most of them zero, some are empty (just for show) and like I mentioned in the beginning, I also set $/ to a newline character, and $\ to space. This also made it possible to make \/ look like I was escaping slashes in the "regexp". So in reality, this code looks like this:
    print "\n0000   00  000  0  0 \n   0  0  0 0  0 0  0 \n   
    0  0000 000  0000 \n   0  0  0 0    0  0 \n000   0  0 0   
     0  0\n";
    
    Which, of course, will print:
    0000   00  000  0  0
       0  0  0 0  0 0  0
       0  0000 000  0000
       0  0  0 0    0  0
    000   0  0 0    0  0
    
    Please point out if something didn't make sense, was unclear (or somehow wrong), and I'll of course fix it. Any comments also very much appreciated (thanks grinder!).
    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.

    Edit: chipmunk 2002-02-28

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found