in reply to My 1st post (japh)

Most of the second and third lines are devoted to initializing $a (and $| as a side effect):
||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g
The two unpacks generate an array consisting of the number 14417713111218131332253147132969324349431334211136532212511512172112293224231453242. The decimal digits of this number are then extracted via =~/./g and used to run-length decode a bit string 1000011110... via map--$|x$_. Since the number of decimal digits is odd, the last value of $| is 1.

After we remove the initialization code and the trailing #JAPH, comment we have:

{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a)x2,$_,256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}
The expression substr(($a)x2,$_,256) produces a copy of the bitstring rotated left by $_ characters (assuming 0<=$_<256). The map sets $_ to 7 and 249 producing the bitstring rotated left by 7 characters and rotated right by 7 characters respectively. These bitstrings are passed to sub{pop^pop} which XORs them together. They are then further XORed with the original bitstring.

The unpack separates the bitstring into groups of 8 bits, and the pack converts the first 25 groups into characters. The substitution converts everything but letters and commas into spaces. The next statement sets the output line ending to a CR unless the first letter of $_ is a J in which case it sets it to the input line ending. The final redo starts over at the beginning of the block.

The rotate-and-XOR operation used in this program has period 128, so every 128 iterations the JAPH string is printed. The initial bitstring becomes the JAPH string after 67 iterations. I note with interest that the bytes after the end of the JAPH string are not all binary zeros.

Replies are listed 'Best First'.
Re^2: My 1st post (japh)
by blazar (Canon) on Nov 26, 2004 at 16:26 UTC
    You're right about everything. Incidentally this was not meant as a challenge or anything like that. However your exposition is as terse and clean as one could have been.

    The bytes "beyond JAPH" are not zeroes for I tried to take advantage of the remaining 56 degrees of freedom. (The lenght of the string must be a power of two for the periodicity effect to take place.)

    The wrong assumption I had initially done was that due to the belonging of 'a'..'z' and 'A'..'Z' to a restricted part of the set of all 256 charachters (especially "in terms of individual bits"), somewhere along the orbit of the transformation, and for a fortunate choice of the remaining bits I would have got a particularly "simple" string, for a sensible definition of "simple", i.e. something that I could code with ease in a sufficiently small space.

    So the further unpack()s where not expected at all in the beginning. Also, I had thought of an extensive search over all 2^56 remaining 7-bytes strings, 63 odd rotate values and 127 iterations of the transformation. On a second thought, considerations inherent to the limited duration of the universe , human life compared to it, and computing power available, convinced me to try a random search instead (wrt the 7-bytes strings).

    I got the string I'm actually employing after running my brute force search program for a while. It is nice in that (i) it yields a short enough coded string, (ii) it doesn't need escaping of chars (in some cases the string contains both "'"s and '"'s), (iii) it needs a resonably high number of iterations to reach the JAPH string.

    It may be worth mentioning that I've been running the search program in the background for a few weeks on a cluster of machines I have access to and it hasn't found a single coded string shorter than the current one, let alone a "better" one. In this connection it may also be worth mentioning that notwithstanding the fact that it had been launched with nice 18, that it caught correctly signals and that it carefully avoided having more than one instance running on each machine, it caught the attention of a few idio^Wother users who complained about it, so that I had to stop it definitely.