It is what is commonly called a JAPH. A purposefully obfuscated piece of Perl code that prints out an innocuous string. So, how does it work? Well, here is the code:
print chr ord scalar qw eof write and print qq pop xor print chr ord qq and quotemeta xor lc print chr ord scalar qw seek fork x keys and print chr ord reverse q each y binmode xor uc print chr ord q defined and int srand print chr ord reverse q kill hex print link and print chr oct ord sqrt oct uc ord scalar qw pack dump xor print chr ord reverse q do rand xor print chr ord q read qr xor print chr int ord reverse qw fileno s printf and print chr sqrt ord reverse q each chomp pack binmode
Let's take off the first level of obfuscation: the quote operators. The operators qw, qq, and q quote the text between a delimiter. Space cannot be a delimiter, so it uses the first non-space character as the delimiter. Here is the code after the effects of the quote operators:
print chr ord scalar ('of', 'writ') and
print "o" xor print chr ord "nd
quotemet" xor lc print chr ord scalar
('eek', 'fork', 'x', 'key') and print chr ord
reverse 'ach y binmod' xor uc print
chr ord 'efine' and int srand print
chr ord reverse 'ill hex print lin'
and print chr oct ord sqrt oct uc ord
scalar ('ack', 'dum') xor print chr ord
reverse 'o ran' xor print chr ord
'ead q' xor print chr int ord reverse
('ileno', 's', 'print') and print chr sqrt
ord reverse 'ach chomp pack binmod'
It is still pretty ugly, but we can start to see the structure. The next layer is the lack of discrete statements. The xor and and operators must execute both sides if the first side is true. All of the statements are true, so xor and and are acting as semicolons. Here is the code after replacing the xor and and operators with semicolons:
print chr ord scalar ('of', 'writ');
print "o";
print chr ord "nd
quotemet";
lc print chr ord scalar ('eek', 'fork', 'x', 'key');
print chr ord reverse 'ach y binmod';
uc print chr ord 'efine';
int srand print chr ord reverse 'ill hex print lin';
print chr oct ord sqrt oct uc ord scalar ('ack', 'dum');
print chr ord reverse 'o ran';
print chr ord 'ead q';
print chr int ord reverse ('ileno', 's', 'print');
print chr sqrt ord reverse 'ach chomp pack binmod'
The next step takes advantage of the fact that a list in scalar context
resolves to the list item. So, scalar ('of', 'writ') is
'writ'. The reverse function in scalar context also
forces scalar context on a list passed to it. So, after applying that
knowledge we get:
print chr ord 'writ'; print "o"; print chr ord "nd quotemet"; lc print chr ord 'key'; print chr ord reverse 'ach y binmod'; uc print chr ord 'efine'; int srand print chr ord reverse 'ill hex print lin'; print chr oct ord sqrt oct uc ord 'dum'; print chr ord reverse 'o ran'; print chr ord 'ead q'; print chr int ord 'tnirp'; print chr sqrt ord 'domnib'
So, now we can see the individual print statements, but it still isn't obvious
what they are printing, and what is the deal with the function before the prints
on lines five, seven, and eight? Well, those functions don't have any effect.
The lc and uc functions turn 1 into 1 (they only effect alphabetical characters),
srand returns 1, and int has no effect on 1 (it turns it into 1). Most of the rest
of the code uses a code like chr ord "string". When ord receives
a string it only looks at the first character and returns its numeric value in the
native character set. The chr function does the opposite. So
chr ord "string" is the same as "s". Here is the code after getting
rid of the useless functions and collapsing the simple chr/ord combinations:
print 'w'; print "o"; print "n" print 'k'; print 'd'; print 'e'; print 'n'; print chr oct ord sqrt oct uc ord 'dum'; print 'n'; print 'e'; print 't'; print chr sqrt ord 'domnid'
At this point we can see that it is printing "wonkden", something, "net", and something.
The next bit only works on ASCII systems. The ASCII value of 'd' is 100. The oct function
interprets the value passed into it as a octal number and returns the corresponding decimal
number. The value 100 in octal is 64 in decimal. The square root of 64 is 8. The ASCII
value of 8 is 56. The value 56 in octal is 46. The ASCII character 46 is '.'. Yeah, that
is a long way to go to just get a '.', luckily the next one is a lot simpler. It starts at
100 as well (ord 'd'), but just takes the square root (10) and turns it into
its corresponding ASCII character: the linefeed character. The PerlIO layer will turn
it into whatever the end of line character is on this platform. So, in the end, all of
that code boils down to:
print "wonkden.net\n";
The most important skill a programmer can have is the ability to read.