Obfuscated, trilingual

A

aarklon

Hi all,

can any one explain how this code works
main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}
The o/p is unix

i got this program from peter van der lindens book just java 2.0 for
fun.

i tried this
printf("%s",(unix)["have"] + "fun" );
but it is not printing any thing

author then proceeds as follows:-


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?

(Please note :- I have n't tested these programs)

/* Just Java
Peter van der Linden
April 1, 1996.

\u0070\u0075\u0062\u006c\u0069\u0063\u0020

\u0050\u0076\u0064\u004c
\u0020\u0031\u0020\u0041\u0070\u0072\u0039\u0036

\u002a\u002f\u0020\u0063\u006c
\u0061\u0073\u0073\u0020\u0068\u0020\u007b

\u0020\u0020\u0070\u0075\u0062\u006c
\u0069\u0063\u0020\u0020\u0020\u0020

\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0020\u0076\u006f
\u0069\u0064

\u006d\u0061\u0069\u006e\u0028\u0020\u0053\u0074\u0072\u0069\u006e
\u0067

\u005b\u005d\u0061\u0029\u0020\u007b
\u0053\u0079\u0073\u0074\u0065\u006d

\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e
\u0074\u006c\u006e

\u0028\u0022\u0048\u0069\u0021\u0022\u0029\u003b\u007d\u007d
\u002f\u002a

*/



% 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

\u002a\u002f\u002f*/



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



public class b {
public static void

/*The main routine */ main (
/* The number of arguments \u002a\u002f\u002f*/ int argc,
/* The array of argument strings */ String
argv[] )

{
System.out.print("Hi!\n");
}
/*\u002a\u002f}/**/

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?
 
R

Richard Bos

can any one explain how this code works
main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

It doesn't.
The o/p is unix

Not in ISO C, it ain't.

You should learn C before you study such foolishness. You don't take a
Bugatti Veyron to the M25 when you've only been behind the wheel three
times before, either, do you? Well, apply the same common sense to
programming.

Richard
 
V

vippstar

Hi all,

can any one explain how this code works
main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

That was not made with compliance to the standard in mind.
Assuming 'unix' is an integer object that holds the value N:

&unix["foo"] equals "foo" + unix
(unix)["foo"] equals "foo"[unix]
As you see, that is not obfuscated at all nor standard.
It is possible to obfuscate code and keep it compliant to ISO C, and
this snippet has failed to do both.
 
R

Richard Tobin

can any one explain how this code works
main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

Unix C compilers often used to #define unix to be 1.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top