Wednesday, 26 December 2012

C/C++ Puzzles: PART - 11

The Obfuscated C Code
  
  What is obfuscation? Simply speaking it is the art of complicating simple things so that others won't understand your intentions. The same principle can be applied to programming. There are two ways of writing programs. The first one is to write simple code which can be understood by anyone. This is a good quality expected from a programmer working in a Team. The second approach is to write code which can not be understood by anyone. This may not be a highly desirable situation always. But there are many reasons why people write such obscure code. To protect the logic of the code, to hide malicious code, to participate in competitions etc are some reasons. There are contests where you have to write obscure code to win. One such contest is the International Obfuscated C Code Contest. Click here to view the official website of IOCCC. 

The C program I wrote below will give you an idea about Program Obfuscation.

#include <stdio.h>
#include <string.h>
#define _______ ;
#define What p##r##i##n##t##f(
#define is "%s\n"
#define This ,_____);}
#define ______ m##a############i##n
#define __o__ int
#define __0__ char
#define __O__ strcpy
#define ooo ++
#define oo /2
__o__ ______(__o__ __, __0__
*___[]){__o__
_=0;__0__ ____[32]_______ __0__ _____
[32] _______ __O__
(____,"aHbeglhl1oj oWuotrklmdq!b"
) _______
for (_=0 _______
_<26 _______ _ ooo )_____[_ oo ]
=____[++_] _______
What
is
This


Download.

The Output of the Program is Shown Below

I have used the Token-Pasting operator (##) and the fact that underscore ( _ ) is a valid identifier to obfuscate the C program.

I think the C program given below is even better.

#include<stdio.h>
#define _ ;
#define __ ,
#define ___ (
#define ____ )
#define _____ {
#define ______ }
#define _______ +
#define ________ printf
#define _________ scanf
#define __________ while
#define ___________ int
#define ____________ main
#define OO =
#define OOO 1
#define o "
#define ooo "%d"
#define oooo <=
#define o00o *
#define o0o &
#define o000o [
#define oo0oo ]
#define o0 char
o0 __0__ o000o 20 oo0oo OO _____ 69 __ 78 __ 84 __ 69 __ 82 __
32 __ 78  __ 79 __ 58 ______ _
o0 __00__ o000o 30 oo0oo OO _____ 70 __ 65 __ 67 __ 84 __
79 __ 82 __ 73 __ 65 __ 76 __ 32 __ 73  __ 83 __ 58 ______ _
___________ ____________ ___ ____
_____
  ___________ O OO OOO  __ OOOO __ OOOOO OO OOO _
  ________  ___ __0__ ____ _
  _________ ___ ooo __ o0o OOOO ____ _
  __________ ___ O oooo OOOO ____
  _____
    OOOOO OO OOOOO o00o O _
    O OO O _______ OOO _
  ______
  ________  ___ __00__ ____ _
  ________ ___ ooo __ OOOOO ____ _
______


The Output of the Program is Shown Below

Here also I used the fact that Underscore ( _ ) is a valid identifier in C. The program finds the factorial of a number. The messages are printed using the ASCII values of letters. That is the reason why you don't see any letters in the program.

No comments:

Post a Comment