I guess you already know about IOCCC. But if you don’t, here is an example application I wrote. That surely isn’t one of the most well written examples, but since it is my first obfuscated c program, I think it is also enough :)
I didn’t obfuscated it using #define’s since by using -E gcc’s option you can easily retrieve the starting code. This is really a obfuscated, chaotic program. And, of course, I won’t give you the solution (but if you understand what it does, please let me know)!
There’s an issue: this code doesn’t fit into the blogspot layout. I really have to make a personalized layout that allow me to include code snippets.
#include <stdio.h>
#include <string.h>
int bl(const char *) ;; int main (int na , char **a) { if (na != 2) return -1;;
printf("%cn", bl (*(a + 1)) + '0'); return 0; } int bl(const char *expr) { int
len = strlen(expr) * 2, i = 0, b = 0; enum S { $S, BO, BC, $E }; enum S s = $S;
char x; while (s != $E && i < (len / 2)){ x = *(expr + i); if (x == ' ') { i++;
continue; } switch (s) { case $S: if (x == 'x28') { s = BO; b++;} else s = $E;
break; case BO: case BC: if (x == 'x28') { s = BO; b++;} else if (x == 'x29')
{ --b; if (b == 0) { s = $S;; } else s = BC; } else { s = $E; } break; case $E:
default:return 1;break; } i++; } if ((b != 0) || (s == $E)) return 1;return 0;}
It uses a state machine to check if the input has balanced parentheses. The use of ‘$’ in identifiers is non portable, by the way.