Guess What This Java Code Does (2)

Let’s play a game. I wrote a little Java program today for fun. As you’ll see I purposefuly obfuscated the code.

There are two parts to this game.

1.) See if you can figure out what the program does.

2.) If you know Java, see if you can make my code any smaller. The current version is 562 bytes, but I’ll bet somebody can find a way to make it even tinier.

Good luck.

F.java:


import java.io.*;public class F{public static void main(String[]a)throws Exception{char[]m=new char[30000];String d="";FileReader f=new FileReader(a[0]);int p=0,i=0,h,n;while((h=f.read())!=-1)d+=(char)h;for(;i<d.length();i++){n=1;switch(d.charAt(i)){case'+':m[p]+=2;
case'-':m[p]--;break;case'.':System.out.print(m[p]);break;case',':m[p]=(char)
System.in.read();break;case']':if(m[p]!=0)while(n>0)switch(d.charAt(--i)){case']':n+=2;case'[':n--;}p++;case'<':p--;break;case'[':if(m[p]==0)while(n>0)switch(d.charAt(++i)){case'[':n+=2;case']':
n--;}p--;case'>':p++;}}}}

Reader Comments (reply)

  1. dan says...

    retrieves a file from a webserver and displays it on your machine

    ...on July 17th, 2007
  2. Ryan says...

    Brainfuck!

    Input file = “++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++.———.———.-.[.”

    Part 2 probably not coming soon.

    ...on July 20th, 2007

Post a Comment (rss)

Powered by WP Hashcash