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...


In reply to (Blue - SPOILER) Re: Re: JAPH the First by Blue
in thread JAPH the First by Blue

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.