Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: JAPH the First

by r.joseph (Hermit)
on Dec 06, 2000 at 08:22 UTC ( [id://45172]=note: print w/replies, xml ) Need Help??


in reply to JAPH the First

As you probably have noticed from my recent appearence, I am new to PM. I am really interested in the whole obfuscation topic (addicted might be more like it) because, apart from being a wonderful time killer (and much time does it kill), it is a great way to learn Perl and amaze your idiot friends :-).

I digress - I was wondering if someone, maybe Blue if he were so inclined, could explain this JAPH because I have tried for quite some time, to no avail, to de-obfuscate it and it seems really interesting. Thanks in advance for any help that is offered!

Replies are listed 'Best First'.
Re: Re: JAPH the First (SPOILER!)
by extremely (Priest) on Dec 06, 2000 at 09:38 UTC
    Trick number one in parsing em, Add white space...
    @_=(4,-16,17,-12.4,9,-13.17,-8.14,8,-19.4,0,18,14,-20.17,5,6,11 ,-7.19,10,2,3,1,-15.7);do{($=,$-)=(@_[$_]>=0?(-@_[$_],$_):split /\./,@_[$_]);$$[-$=]=pack q#C#,$-+=65;}foreach(0..$#_);print@$; # becomes. Note the # comments on some lines @_ = # @_ is a special list variable, thus =( implies a list. ( 4,-16,17,-12.4,9,-13.17, # big list of data... 22 in fact -8.14,8,-19.4,0,18,14, # lots of decimals -20.17,5,6,11,-7.19, # lots of negatives 10,2,3,1,-15.7 ); # ); is end of list. do { # do turns a block into a statement that can take loop modifiers ($=,$-)= # $= and $- are print format variables # wrapped in parens, they want a list. ( # ahh, a paren for a list! @_[$_] >= 0 # Conditional test for the ?: operator + tests for negative ? ( -@_[$_], $_ ) # If true, return a list of -neg value +, counter : split /\./ , @_[$_] # If false, split on . ); # end of assignment list $$[-$=] = # oh god is @$ a legal array? *sob* yes... # what does a negative array count do? pack q#C#, $- += 65; # pack 'C' is for unsigned chars # 65 is the offest to lowercase 'a' in asc +ii } foreach (0..$#_); #loop modifier for do block #loops from 0 to 21, the size of @_ print @$; #print the array!

    Does that help any? You generally have to read character by character and be aware of the special variables to parse these things, then you start spotting structures once you see the variables and assignments.

    --
    $you = new YOU;
    honk() if $you->love(perl)

(Blue - SPOILER) Re: Re: JAPH the First
by Blue (Hermit) on Dec 06, 2000 at 20:23 UTC
    extremely did a good job explaining it; let me go into a bit more detail, as well as some thought on the process. This is definitely a spoiler, don't read further if you want to try and crack it.

    The Anatomy of JAPH the First

    First things first I figured that I wanted an interesting way to generate the "Just Another Perl Hacker" string. I'll often see it character rotated or other encryption, usually in groups of 4,7,4,6 (number of letters) per word. I didn't want that so I had to come up with an alternate way to store it.

    Looking at it cryptographically, of which I have no experience except that I used to do caeser encyption (A=I, B=J, C=K, ... for one example) when I was a kid and had recently read Neal Stephenson's excellent book Cryptinomicon, I noticed that it was a rather flat distribution of letters - except for the (A,E,H,R,T) there were no repeats. I figured I could use this.

    I created an array where the data wasn't the JAPH phrase directly, but rather an order for the output. The 1st element of the array represented an A simply by being the first element, the second element was B, the third element was C, and so on. The value of the element showed where in the output to put the character. So the value of 1st element being 4 meant put an "A" as the 4th character of the output.

    However, some characters were not used, and some characters were used more then once. I figured I could use those unused letters to show the missing characters. I figured I'd make them negative in order to pick them out. Well, I originally was going to have the same thing, but offset, such that and negative element still stored the position but was a different character. However, since there were 3 Es and 3 Rs I couldn't do it directly. Instead, I cheated and encoded two pieces on information in each value, seperated by a decimal point to keep it looking like a number. The "integer" part was the normal position modifier, the "decimals" part was which character, same as the array (A=0, B=1, etc.).

    Once I had my data encrypted, I just needed to decrypt and print. I looped through the input, checking for positive or negative values. In both cases I would have a position from the data, in some cases I would have character by which array element, and others by the "decimals" part of the data. So I returned both as a list. Since position was already negated in the data for one case, I figured it would be more obsure to negate the other part.

    I then re-negate the position building an array for output, and put in the character. I didn't want to use chr(), it was too obvious, so instead I had the only mostly obvious pack doing the same work.

    Finally, my program printed the output array. Because of context there were no spaces added between elements.

    At that point, I went back over my code, eliminated as much readability and whitespace as I could, and changed all of my variable names to special characters that would not effect the output. $= and $- were naturals because they would help hide operators I was working with, but @$ just made me sit back and grin an evil little grin. $; was also considered.

    Hope this was helpful for anyone looking at doing their own JAPH, or just interested. It was fun to do. And writing this has given me some ides for my next.

    Happy Holidays,
    =Blue
    ...you might be eaten by a grue...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found