Skip to content

Instantly share code, notes, and snippets.

@jotaki
Created January 14, 2012 15:46
Show Gist options
  • Save jotaki/1611836 to your computer and use it in GitHub Desktop.
Save jotaki/1611836 to your computer and use it in GitHub Desktop.
Obfuscated Hello, World
/* compile with gcc -o obfhello obfhello.c -lm */
#define xR return
# define T typedef
# define E extern
# define S static
# define P putchar
# define Z ((V*)0)
#define Bb main
# define X int
# define A char
# define H void
# define Q sqrt
# define G double
#define U 3
T X Y;T A C;T C** O;T H V;T G D;E D Q(D x);E Y P(Y c);S Y (*o)(Y c)=P;S D
(*f)(D x)=Q;S Y s_(M)Y M;{xR(Bb(M,Z));}S Y _[]={(9*31+22)*10+56*2+14,(((U*15+72)
-1)/2+17)*1.4-5,12*U,1*100+9*11-U,(0x2357*2.3-72.1)*-1,-((1<<9)+(1<<U)*34),(1<<
13)+(125<<U)+(U*8),32767>>5^2047,((4*16<<1)-(9*2))*U+70,-1024,-(66*10+16),-24*
1000-(900+(1<<6)),-3136,(2*256)^-768,225*4};Y Bb(I,v)Y I;O v;{S Y _0=0;xR(v!=Z?
s_(0110):(0<I)?o(I),s_((_0+=1,I+((((0>(_0-1)[_])?-1*(Y)f(-((_0-1)[_])):(Y)f(
(_0-1)[_]))>>1)^_0))):0);}
@iank
Copy link

iank commented Jan 14, 2012

extern double sqrt(double x);
extern int putchar(int c);

static int buf[]={
    3136,100,36,196,-20736,-784,9216,1024,400,-1024,-676,-24964,-3136,-256,900
};

int main(int I, char **v) {
    static int idx=0;
    if (v!=0) {
        main(0110,0);
    } else {
        if (I > 0) {
            putchar(I);
            int p;
            if (buf[idx] < 0) {
                p = -1*sqrt(-1*buf[idx]);
            } else {
                p = sqrt(buf[idx]);
            }
            idx++;
            p = p >> 1;
            p^=idx;
            main(I+p,0);
        }
    }
}

@iank
Copy link

iank commented Jan 14, 2012

static int buf[]={
    3136,100,36,196,-20736,-784,9216,1024,400,-1024,-676,-24964,-3136,-256,900
};
static int idx=0;

int main(int I, char **v) {
    int sign,n,p;
    if (v!=0)
        return main(72,0);

    if (I <= 0) return;
    putchar(I);
    n = buf[idx++];
    sign = n/abs(n);
    p = sign * sqrt(abs(n));
    p = (p >> 1) ^ idx;
    main(I+p,0);
}

@iank
Copy link

iank commented Jan 14, 2012

static int buf[]={
    3136,100,36,196,-20736,-784,9216,1024,400,-1024,-676,-24964,-3136,-256
};
static char c = 'H';

int main() {
    int sign,n,p,i;
    for (i = 0; i < 14; i++) {
        n = buf[i]; sign = n/abs(n);
        p = sign * sqrt(abs(n));
        p = (p >> 1) ^ (i+1);

        putchar(c);
        c += p;
    }
}

@iank
Copy link

iank commented Jan 14, 2012

char *str = "Hello, World!\n";
static int off[14];

int main() {
    int sign,p,i;
    for (i = 1; i <= strlen(str); i++) {
        p = str[i] - str[i-1];

        sign = p == 0 ? 1 : p/abs(p);
        p ^= (i);
        p = (p << 1);
        p = sign * p*p;

        off[i-1] = p;
    }

    int n;
    char c = str[0];
    for (i = 0; i < strlen(str); i++) {
        n = off[i]; sign = n/abs(n);
        p = sign * sqrt(abs(n));
        p = (p >> 1) ^ (i+1);

        putchar(c);
        c += p;
    }
}

@iank
Copy link

iank commented Jan 14, 2012

static int off[]={
    'e' - 'H',
    'l' - 'e',
    'l' - 'l',
    'o' - 'l',
    ',' - 'o',
    ' ' - ',',
    'W' - ' ',
    'o' - 'W',
    'r' - 'o',
    'l' - 'r',
    'd' - 'l',
    '!' - 'd',
    '\n' - '!',
};
static char c = 'H';

int main() {
    int i;
    for (i = 0; i < 14; i++) {
        putchar(c); c += off[i];
    }
}

@iank
Copy link

iank commented Jan 14, 2012

static char *str = "Hello, World!\n";

int main() {
    int i;
    for (i = 0; i < strlen(str); i++) {
        putchar(str[i]);
    }
}

@iank
Copy link

iank commented Jan 14, 2012

int main() {
    puts("Hello, World!");
}

@iank
Copy link

iank commented Jan 14, 2012

Q.E.D.

@jotaki
Copy link
Author

jotaki commented Jan 14, 2012

iank wins! \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment