Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

japhy's 2nd obfuscation review

by japhy (Canon)
on Aug 25, 2001 at 00:15 UTC ( #107688=obfuscated: print w/replies, xml ) Need Help??

My current signature

Perhaps this looks familar to some of you. ;)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
Well, the first thing to notice is that we start with a substitution.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
We're using + as the delimiter. Clearing away the cruft, we have:
s//=END;/+y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
So this substitutes "=END;" for nothing, in $_. The next character is for addition; let's add some whitespace to help make this more visible.
s//=END;/ + y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
Next we have a translation via the y/// operator, which is just a sed-like synonym for tr///.
s//=END;/ + y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
The first set of characters has () as its delimiter, and the second set has }} as its. That's a sneaky little trick few Perl'ers know -- if you use a set of paired delimiters for the left-hand side of a s/// or a tr///, you can use ANY delimiter you want for the right-hand side; they don't have to use the same delimiter, or even be paired delimiters.

I'm also going to expand all the ranges in the classes, and structure it so you see exactly what gets changed to what. Notice how the interior of the right-hand side appears to contain two more y///'s -- one with y jjj and one that simply appears to be incomplete. Oh, and the ;-P is meant to be a smiley.

s//=END;/ + tr{;<=>?@ABCDEFGHIJKLMNOP}
              {y js++=;shajsj<++y(pq)}
?print:??;
If we remove all the unneeded junk, we see that we're merely replacing "=END;" with "japhy".
s//=END;/ + tr{;=DEN}
              {yjhap}
?print:??;
Next, we have a question mark -- at this point, it indicates the ternary operator, ?:. To its left, then, is the conditional. The conditional is the sum of our subtitution (1) and our translation (5), which is 6, a true value.
(s//=END;/ + tr/;=DEN/yjhap/) ? print : ??;
The expression executed for "true" is simply to print $_, which is what happens -- and "japhy" gets printed. The other expression is ??, which is an empty m?? regex. Although entirely unimportant and unrelated, the proximity of these ?'s to the other one is a "nice" thing.

Therefore, the code becomes:

(s//=END;/ + tr/;=DEN/yjhap/) ? print : ??;

# or

s//=END;/;        # $_ = "=END;"
tr/;=DEN/yjhap/;  # "=END;" => "japhy"
print;            # print $_

The True Nature of Perl

Here's a playful one that is meant to delight and amuse.
$^X and @ X=$^F**$^F;(
$^X )=(
$^X )=~m #perl#; die
$^X  =~m|[parley]{@X}|; $g or die(
$^X );chop(@  XX=q q3";q^(
$^X ));(
$^X )=~s|[parley]{@X}|@XX$/|cgi; $g or die(
$^X );
This was fun to write.

I'll get back to this one on Sunday. I'm leaving now for a weekend retreat with my fraternity.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: japhy's 2nd obfuscation review
by tlhf (Scribe) on Aug 26, 2001 at 07:31 UTC
    I liked your 'delightful' one :) Took me a while to figure it out, but it's a bit sneaky in that's it almost all trickery magic. I got the obfuscated bit down too:
    ($^X ) = ($^X ) =~ m/^ |perl|;/g; @XX = '3"; ' ^ (per); ($^X ) =~ s/[perl]{4}/@XX/; print("$^X\n");
    The CGI bit comes from matching the '3"; ' ^ (per);. I especially liked the first $g or die, took me a while to realise the whole thing was a match starting with the $ on line 4.
Re: japhy's 2nd obfuscation review
by Sigmund (Pilgrim) on Aug 27, 2001 at 17:13 UTC
    Hey, buddy,
    this is great!!! i spent three hours trying to decipher your signature the morning before you posted explanations!!! I'm happy to see that i understood everything, but I said, it took me three hours!!!
    being honest, i hadn't understood the last two question marks...i didn't remrmber that the m in the m/// operator could be omitted!!!
    thanks for your lesson! it taught me many many things.
    SiG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://107688]
Approved by root
help
Chatterbox?
[ambrus]: Corion: from the docs, it definitely looks like it would be possible to write an AnyEvent driver for it using Prima::File and Prima::Timer.
[ambrus]: (I haven't found an idle event.)
[ambrus]: However, I also looked at the internals, and found two interesting things:
[marto]: stupid xpath question, I have a xpath copied from the browser, is the * wildcard supposed to work for IDs? e.g. '//*[@id="*"]/ div/div/header/p/a '?
[ambrus]: The main loop for unixish systems is in https://metacpan. org/source/ KARASIK/Prima-1. 49/unix/apc_app.c. It is a hand-rolled select loop, but also always spins at least once every 0.2 seconds for some reason.
[ambrus]: marto: no, not that way. if you just want to test for an existing id attribute, then write *[@id] , or you can match a regexp to the value of that attribute like *[@id=~/something/ ]
[marto]: ambrus, thanks I ended up going with '//*[starts- with(@id, "thread_")]...
[ambrus]: Sometimes it's easier to just match elements in ways other than xpath, like directly with perl code.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-12-08 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (140 votes). Check out past polls.