in reply to Re: JAPH the First
in thread JAPH the First
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...
|
|---|