Do you understand how work the code of the worst abuse of the C preprocessor category of 1986 winner.

Olivier Guyot
4 min readOct 22, 2020

Do you know what does obfuscated means ?

Obfucated in coding is a way to make a code unintelligible, unclear in order to protect its used. There is some competition where people have to create a obfuscated C code.

Let’s go to understand this concept throught the analyse of the 3rd International Obfuscated C Code Contest (1986) winner.

What’s the International Obfuscated C code contest?

According to wikipedia : The International Obfuscated C Code Contest(abbreviated IOCCC) is a computer programming contest for the most creatively obfuscated C code. Held annually, it is described as “celebrating [C’s] syntactical opaqueness”

Lets analyse the code of the worst abuse of the C preprocessor category of 1986.

The code author was :

#define DIT (
#define DAH )
#define __DAH ++
#define DITDAH *
#define DAHDIT for
#define DIT_DAH malloc
#define DAH_DIT gets
#define _DAHDIT char
_DAHDIT _DAH_[]="ETIANMSURWDKGOHVFaLaPJBXCYZQb54a3d2f16g7c8a90l?e'b.s;i,d:"
;main DIT DAH{_DAHDIT
DITDAH _DIT,DITDAH DAH_,DITDAH DIT_,
DITDAH _DIT_,DITDAH DIT_DAH DIT
DAH,DITDAH DAH_DIT DIT DAH;DAHDIT
DIT _DIT=DIT_DAH DIT 81 DAH,DIT_=_DIT
__DAH;_DIT==DAH_DIT DIT _DIT DAH;__DIT
DIT'\n'DAH DAH DAHDIT DIT DAH_=_DIT;DITDAH
DAH_;__DIT DIT DITDAH
_DIT_?_DAH DIT DITDAH DIT_ DAH:'?'DAH,__DIT
DIT' 'DAH,DAH_ __DAH DAH DAHDIT DIT
DITDAH DIT_=2,_DIT_=_DAH_; DITDAH _DIT_&&DIT
DITDAH _DIT_!=DIT DITDAH DAH_>='a'? DITDAH
DAH_&223:DITDAH DAH_ DAH DAH; DIT
DITDAH DIT_ DAH __DAH,_DIT_ __DAH DAH
DITDAH DIT_+= DIT DITDAH _DIT_>='a'? DITDAH _DIT_-'a':0
DAH;}_DAH DIT DIT_ DAH{ __DIT DIT
DIT_>3?_DAH DIT DIT_>>1 DAH:'\0'DAH;return
DIT_&1?'-':'.';}__DIT DIT DIT_ DAH _DAHDIT
DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}

Use of macro

The first things that we can see is that the author have you the #define declaration in order to replace some words. In C it’s called a macro. He replaces <DIT by (> <DAH by )><__DAH by++><DITDAH by *>
<DAHDIT by for><DIT_DAH by malloc><DAH_DIT by gets><_DAHDIT by char>

What happened after compiling this code ?

After compiling we received some error but the file h was created.

Then we launch the program

The program ask us an input and it will translate our input written with alpha character into a morse language,

The written code is really complicated, lets look to the pre processing code.

After using the gcc -E hague.c -o my code. We can dispay this result.

You know that every function are at least separated by { } ( like if or for statement in C ),

Here we can see that we have found 3 separation. In fact there is 3 functions. The first is the main, the second the function used to convert ( but you will be able to read it after)m and the thirst to display a result like a putchar function.

Now lets make it more readable. We know that every line could end by a ;

lets reformat with that.

Now we can see that last function which look like to the write function. let’s replace the function by a name; __DIT by funcA, _DIT_ by var1, _DIT, by var2, DIT_ by var3, DAH_ by var4 ( on vim :%s/<word>/<words to replace/g)

Don’t forget that ; is also used in for loop

We can see 3 loops so we can regroup them

It s much more readable, because we can see the 3 for loop and the incrementation.

For first for loop
Initial condition : var2=malloc ( 81 ),var3=var2++
Stop condition : var2==gets ( var2 )
Last event : funcA (‘\n’)

For second for loop
Initial condition :var4=var2;
Stop condition: *var4
Last event: funcA ( *var1?_DAH ( * var3 ):’?’),funcA(‘ ‘),var4 ++

For third for loop
Initial condition:* var3=2,var1=_var4
Stop condition: * var1&&(* var1!=( * var4>=’a’? *var4&223:* var4 ) )
Last event: (* var3 ) ++,var1 ++

It will loop on the var to print the correct morse value and translate if if needed with the second function _DAH
This function _DAH will use a var and translate if when called

Thank you for reading and i hope you have understood how does this code won the competition this years.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Olivier Guyot
Olivier Guyot

No responses yet

Write a response