Some Light Relief—The Domestic Obfuscated Java Code Non-Competition

Readers of my book Expert C Programming will be aware of the International Obfuscated C Code Competition (IOCCC). It's an annual contest run over Usenet since 1984 to find the most horrible and unreadable C programs of the year. Not horrible in that it is badly written, but in the much subtler concept of being horrible to figure out what it does and how it works.

The IOCCC accepts entries in the winter, which are judged over the spring, and the winners are announced at the summer Usenix conference. It is a great honor to be one of the dozen or so category winners at the IOCCC, as many very good programmers turn their talents to the dark side of the force for this event. If you know C pretty well, you might be interested in figuring out what this IOCCC past winner does:

main() {printf(&unix["21%six12"],(unix)["have"]+"fun"-0x60);}

Hint: It doesn't print “have fun.”

Here, in the spirit of the IOCCC, are two Java programs that I wrote for April Fool's Day a few years back. You should be pretty good at reading Java code at this point, so I won't spoil your fun.

This program looks like one big comment, so it should compile without problems. When you run it, it greets you! But how?

/*   Just Java
     Peter van der Linden
     April 1, 1996.
u0070u0075u0062u006cu0069u0063u0020
 u0050u0076u0064u004cu0020u0031u0020u0041u0070u0072u0039u0036
  u002au002fu0020u0063u006cu0061u0073u0073u0020u0068u0020u007b
   u0020u0020u0070u0075u0062u006cu0069u0063u0020u0020u0020u0020
    u0073u0074u0061u0074u0069u0063u0020u0020u0076u006fu0069u0064
     u006du0061u0069u006eu0028u0020u0053u0074u0072u0069u006eu0067
      u005bu005du0061u0029u0020u007bu0053u0079u0073u0074u0065u006d
       u002eu006fu0075u0074u002eu0070u0072u0069u006eu0074u006cu006e
        u0028u0022u0048u0069u0021u0022u0029u003bu007du007du002fu002a
 */

% javac h.java

% java h

Hi!

The second program is my attempt to greatly improve program portability. This one source file can be compiled by an ANSI C compiler and executed. The same code can also be compiled and executed by a Java compiler and by a C++ compiler! Was that a great day, or what? True source portability! Every program should do as well. This program is on the website www.afu.com/jj6.

/*  Peter van der Linden,   "Just Java"
    April 1, 1996
    Real portability: a Java program, C program and C++ program.

    Compile and run this Java program with:  javac b.java     java b
    Compile and run this C program with:     cc    b.c         a.out
    Compile and run this C++ program with:   CC    b.c         a.out
    u002au002fu002f*/

#define String char*
#define t struct
#include <stdio.h>
t{t{int(*print)(const char*,...);}out;}
System={{printf}};/*u002au002f

public class b {
                               public static void
/* The main routine                          */     main (
/* The number of arguments u002au002fu002f*/          int    argc,
/* The array of argument strings             */          String argv[] )
                       {
                             System.out.print("Hi! ");
                       }
/*u002au002f}/**/

How does this trilingual program work?

Please don't suggest an International Obfuscated Java Code Competition! It works for C because there are so many opportunities to abuse the preprocessor, the expression semantics, the library calls, and so on. Java doesn't offer half as many opportunities to unscrew the unscrutable, so let's keep things that way, OK?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.26.108