Make the simplest code unreadable

Just for fun I made a simple code, as unreadable as possible.

The result:

    public static void main(String[] args) {
        String txt = "";
        for(int i=0; i<6; i++){txt += txt .length() == 0 ? "h" : txt .length() == 2 ? "j" : i == 3 || i == 4 ? (txt .charAt(txt .length()-1) == ' ' ? "d" : " ") : i == 5 ? "å" : "e";}
        System.out.println(txt);
    }

I would love if you could make your own version, and see how bad it can get.

I’ve seen worse in production.

The same in a one liner:


public static void main(String[]args){String txt="";for(int i=0;i<6;i++){txt+=txt.length()==0?"h":txt.length()==2?"j":i==3||i==4?(txt.charAt(txt.length()-1)==' '?"d":" "):i==5?"å":"e";}System.out.println(txt);}

This shit compiles and runs.


\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u004a\u0047\u004f\u0020\u007b\u0020\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0061\u0072\u0067\u0073\u0029\u0020\u007b\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0022\u004c\u0061\u006d\u0065\u0020\u003a\u006f\u0028\u0022\u0029\u003b\u0020\u007d\u0020\u007d

This is how I commit code to the evil corporations, to keep it safe from prying eyes. :point:

Adding some unnecessary instructions to my previous one:


public static void main(String[]a){String t="";for(int i=0;i<Integer.MAX_VALUE;i++){t+=t.length()==0?"h":t.length()==2?"j":i==3||i==4?(t.charAt(t.length()-1)==' '?"d":" "):i==5?"å":"e";if(i==6)break;if(i>6)break;System.out.println("A quick brown fox jumped over the lazy dog.")}System.out.println(t);}

Enhanced FizzBuzz for dummies:


	for (int i=1;i<=100;i++) {
		int a=((528>>i%15-1)&1)*4;
		int b=((-2128340926>>(i%15)*2)&3)*4;
		System.out.println("FizzBuzz".substring(a,b)+(a==b?i:""));
	}

I had a Java book with a lighthearted example of a program written as such that was a valid C, C++, and Java program.

This?? I found this polyglot online.


//\u000a/*
#include <iostream>

#define private
#define public
#define static
#define void int
struct {
  std::ostream &println(const char *c) {
    return std::cout << c < < std::endl;
  }
} out;
//*/
/*\u002a/
import static java.lang.System.out;
public class Polyglot {
//*/
  public static void main(/*\u002a/String[] args//*/
      ) {
    out.println("Hello from whatever language this is!");
  }
/*\u002a/
}
// */

Woo! It’s like playing in the mud!


			private static int[] aa_aa={2,0,6,1,4,3,5};private static int[]
			aa_a_a={0x65,0x134,0x6A,0x64,0x68,0x20,0x00};
			public static void main(String[] args){int aAa=aa_aa[2];
			String aA_aa_="";for(; aaa_(aAa)<97;){aA_aa_+=(char)
			(a_aa(aA_aa_.length())?aa_a_a[4]: aa_a(aA_aa_.length())
			%2.0f==0.0f?aa_a_a[3]:aAa==aa_aa[5]||aAa==aa_aa[4]?
			(a__aaa(aA_aa_)? aa_a_a[3]:aa_a_a[5]):aAa==aa_aa[6]?
			aa_a_a[1]:aa_a_a[0]);aAa=a_a_a(aAa);}System.out.println(
			aA_aa_);}private static char aaa_(int a){return aa_aa[3]
			>a?'a':'A';}private static float aa_a(int aa){if(aa==
			aa_aa[0])return 1.0f;else return 2.0f;}private static 
			boolean a__aaa(String a_aa_a){return a_aa_a.charAt(a_aa_a
			.length()-1)==aa_a_a[5];}private static int a_a_a(int a_a)
			{return a_a+=aa_aa[4];}private static boolean a_aa(int aa)
			{return aa_aa[1]==aa;}


@Riven: What… is… that?

@SHC No, it was longer and more clever, but similar, making more use of the unicode literals.

Python!

"dFg%$rfRo@#gL+n9(ibNm*ca#fgr9a^fv$ya4Tj"[::22 - (11 * 2 + 1)][::9//3]

http://benkurtovic.com/2014/06/01/obfuscating-hello-world.html

Ow.
My brain ! why would you do that

Text as unicode char, the compiler reads it as characters

public class JGO { public static void main(String[] args) { System.out.println("Lame :o("); } }

[spoiler]pls don’t send me to the room[/spoiler]

I once saw a video showing somebody using gimp as ‘IDE’ he draw an image pixel by pixel saved it renamed it to .class and it was the hello world program. I dont remember the video source neither the file format. Is there an image format without header, just a ‘byte array’?

-ClaasJG

I bet only a *.raw image-file can start with 0xCAFEBABE

I bet I am able to let every file start with ‘0xCAFEBABE’ :persecutioncomplex:

You confuse data for information, but enough of this derailing :persecutioncomplex:

Crap, there is a rail? I think I just missed it…

Guessed as much, thanks. I just don’t see how to feed it to a compile without the IDE throwing a tantrum (And I foresee the answer will point out that using an IDE for that is foolish).

I once did try to use asian characters to name classes, just to screw with coworkers not using unicode in their IDE, but my own compiler had a seizure :clue: