Obfuscated C Code
Unless otherwise indicated, the code comes from the International Obfuscated
C code contest. Most files contain an explanatory text file appended to
the ANSI C code. You really need to see the source code to appreciate
most of these.
- Binary Display -- A obfuscated but useful binary
- BlackJack -- An obfuscated Blackjack program.
- Morse Code -- Converts the standard input into morse
code. Also, the source is mostly a bunch of DAH DIT DAH ... etc. which
spells out a message in morse code.
- Twelve bugs -- Output is a parody of
"the twelve days of christmas."
- Smile -- Outputs a cute picture.
- Pictures -- Outputs a stream interesting patterns
on your ghostview displayer. I don't know how to describe exactly what this
program does. You'll just have to play around with it a bit.
- Pig Latin -- An English to pig-latin translater.
The source code is written in pig-latin and the layout is in the shape of a
- Rule Abuse -- 95 percent of the source is one
long comment that contains nothing but seemingly random braces and a few
semi-colons. But these braces and semi-colons are very precisely placed for
if you use the source as input to the program, these braces and semi-colons
become ... Just try it.
- Types Parser -- Returns the type of an
arbitrarily complicated C type given as input (not on the command line.)
E.g. ptr to function of array of ptr returning ... Very short and useful.
- Babble -- An implementation of Charles
Babbage's Analytical Engine that computes factorials, GCDs, and computes a
factor of a number.
- Adder -- Adds two numbers. What's so clever
about that? Check out the source layout! It consists of variations of
the word "main" repeated over and over and placed in the shape of a
circuit diagram for a half-adder. Which is exactly what the program
does; it adds by carrying out the indicated logical bit operations.
- E -- Computes a desired number of digits
of e in any desired base.
- E -- Another obfuscated program to calculate digits
of e. (not from the Contest)
- Pi -- A unique program layout and the most unusual
method of calculating pi I have ever seen. The source code is a circle and
the program works by calculating its own area and diameter, and then doing
a division to approximate pi!! Very bizzare.
- Primes -- Prints out prime numbers. Almost
all of the work is done in the preprocessor!
- Factorial -- Calculates arbitrarily large
factorials very quickly.
- Factor -- Factors large integers rather
- Rot13 filter -- One line filter which
shifts each character 13 places in an alphabetic cycle.
- Palindrome -- Every source code line is a
- Flipper -- Takes a text file and reflects
it across the upper-left to lower-right diagonal. Running this program on
the source file produces a program that works exactly like the
original! As a bonus, a 'secret' message becomes visible in the flipped
version of the program.
- Hello World -- An obfuscated version
of the classic 'hello world' program.
- She loves me, she loves me not, ... --
You must see the source code layout to appreciate this; it reads just like
a series of letters exchanged between charlie and charlotte. This is
- Alphabetize -- The inputs get printed
character by character in alphabetical order. Short and obscure.
- Magic Squares -- Prints out a different magic
square during successive runs. Works for both even and odd orders.
- Maze -- Produces a random maze. Very short and
obscure. (not from the Contest)
- Maze Rat -- A game where you have to solve the maze
from the rat's eye point of view. The maze has enough symmetry that you
feel like you are going in circles forever even when you aren't.
- 3-D Maze -- Solve a 3-D maze. This game is
actually fun to play!
- Obscure -- Short, extremely obscure program
which runs only on the Vax-11 and PDP-11.
- N Queens -- 240 character program which solves
the n-queens problem with chessboard output.
- Puzzles -- Short program for solving the towers
of hanoi and chinese ring puzzles.
- Hanoi -- Program that "solves" the towers of
hanoi puzzle. Actually ALL the work is done in the preprocessor so that the
program doesn't really solve the puzzle, the compiler does! The preprocessor
generates code for a single printf statement with one long string which is
the solution. The resulting program does nothing except print out the
- Othello -- Extremely compact. Has 11 playing
levels. Determines its move via minimax search with alpha-beta pruning with
an evaluation function that depends largely on mobility. All this in only
1K!! and it plays a good game of othello to boot!
- Subsets -- One liner which produces all proper
subsets of the set or arguments passed to it.
- Differential Equations -- Numerically
solves differential equations via the Range-Kutta method. Also, contains
a reversing filter. Not impressed? There's more. Use the reversing filter
on the source code to produce another program which is a shell sort! (the
shell sort has its own reversing filter to reproduce the original). There's
still more. Using the sort program on the original source code produces
another program which generates the fibonacci numbers! This is astonishing!
- Typing Test -- Produces a string by using
pointers to functions that return a struct of pointers to functions. Very
- Where Are You? -- Enter longitude and
lattitude and this will print out a map showing your location. Extremely
- Christmas -- Obfuscated program whose output is
- Christmas -- A short program with Christmas
- BASIC -- A BASIC interpreter, complete with
a lunar landing program.