Obfuscated Main
Between 2001 and 2005, when I was doing my engineering studies, I used to run a mailing list called ncoders which had around 150 members. We used to discuss programming and network protocols in the mailing list.
One day we were discussing how we could obfuscate the
main()
function in C such that the main()
function didn't seem to appear in the code. I wrote the following
code and posted to the mailing list:
#include <stdio.h>
#define decode(s,t,u,m,p,e,d) m ## s ## u ## t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("Stumped?\n");
}
This program compiles and runs successfully. It produces the following output:
Stumped?
The mailing list does not exist anymore. The community disappeared gradually and the mailing list was removed. But the code seems to have survived in the inboxes of some subscribers because if we search the web, we can find so many occurrences of this code.
Here is a quick explanation of the code. In C, ##
is
the preprocessor operator for concatenation.
-
begin()
is replaced withdecode(a,n,i,m,a,t,e)()
, -
decode(a,n,i,m,a,t,e)()
is replaced withm ## a ## i ## n()
, and -
m ## a ## i ## n()
is replaced withmain()
.
Thus effectively, begin()
is replaced with
main()
.