Obfuscated C programs: Introduction

preview_player
Показать описание
If you program long enough, eventually you will run into a programming art category called "obfuscated code" or “code golf”. You can find these especially at IOCCC. In this video I introduce the concept and the basic ideas behind such design. More information below (click "Show more").

I realize the category is "obfuscated code", not "small code", but often trying to compress your code into the smallest size will also effectively obfuscate its function. I also realize that some of the individual changes I did in the video did actually _not_ result in smaller program code size, but the opposite. But the end result is still the shortest I could manage, if you remove the "int", the "return", and the space after "include".
Actual obfuscation techniques include using small and meaningless variable names, using unusual syntax constructs, redefining reserved words, adding code that appears to do one thing but does something else (or nothing at all), creating a complex machinery (such as an interpreter) to do a different task, encryption, and so on.

Source code:

Music:
- Star Ocean :: Encounter :: Motoi Sakuraba (converted into MIDI and played through OPL3 emulation through homebrew software)
- Chrono Cross :: Jellyfish Sea :: Yasunori Mitsuda

Contribute subtitles:

I got to use the word "defenestrate"!

#Bisqwit #Programming #ProgrammingPhilosophy #Tutorial #ObfuscatedCode #CProgramming
Рекомендации по теме
Комментарии
Автор

Idea/Question: is the obfuscated code faster than the normal code?

ParadoxBassCube
Автор

This background music really makes the code even spookier than is already is! ^^

Kniffel
Автор

I just discovered this, and I can only describe you as the Bob Ross of programming.

gubbin
Автор

0:45
_upgrade_
0:54
_upgrade_
1:16
Uhhh... _upgrade_
1:33
Whatever. _upgrade_
1:48
_🅱*_*_*_*_ _*_go BACK_*
1:57
*_aaaarghh my eyes_*
2:05
*_jFC_*
2:44
*_what the frigg did you just 🅱ring upon this cursed land_*
3:15
*_I͠t ͏i̡s ͡a̕l͏ready ̕too lat̸e.̵ T͟h̀e͜ ͟s̷ong ͝t͟ha͟t e̶ņd̸s̨ ͢th̀e̡ ͠w̧or͏l͝d̶ ̛h̸a̧s ̀alrea̡d̸y ̷bee̷n su͝ǹg.̨ ͝Em̢br͘ac͏e̢ th͜e v҉oįd̵. ҉He͝ ͢c̷om͢eeeȩs̛s̛_*

sebastianmorataboada
Автор

As someone with a background in Java and PHP, this is kinda how I felt when I tried to write a server in C for the first time, only 100x worse. It's like going from a power saw to a hand saw that cuts your hand off every time it isn't 100% level.

hattrickster
Автор

This is the first time I've heard someone honestly and casually use the word "defenestrate."

Blue-Maned_Hawk
Автор

I don't know about anyone else, but for me there's a certain area between obfuscated code and readable code when the code seems so elegantly designed, where it doesn't use so many obfuscated concepts as to confuse whoever is seeing it, but it also is compacted in a way that makes everything flow together concisely but beautifully. But I don't know, I haven't seen enough programs to be sure.

OrangeC
Автор

as someone who study the c languague for more than 4 years this so stimulating and satisfying to me

ewncilo
Автор

I don't understand the " characters.. Why and how is this used? Do these characters mean something?

edit: OK.. I understand now.. It translates into the offset.. (You even said it in your video..!)

EmielvanGoor
Автор

my thoughts: 1. Huh. 2. Okay. 3. Sure. 4. Wh-- err.. wh-- ????

WeAreCameron
Автор

Great introduction and breakdown to basic obfuscation techniques. Thanks for the post!

oEQjet
Автор

I was blown away by this one, it took me quite a while to understand why that worked.

tomhijkl
Автор

**Obfuscation**


Makes a 1st Person Shooter with 6 hours playtime using 30 lines of code, full HD, 3D, textured and sound.

Sypaka
Автор

This guy is legit trolling my knowledge of C.

JTST
Автор

Wai wait, hold up
So the dude wrote a program that gets the local time and responds accordingly - IN TWO LINES??
What dark sorcery is this?

dzonialucard
Автор

Amazing explanation and application. Clear, concise, and to the point. Thanks for this!

devjock
Автор

I, while trying to code a short program in C without using semicolon, came across your video and was really mesmerized. I have prepared a full length explanation of each step (... your explanations were sometimes just hints or there were no explanation at all, just like the use of & 7 instead of - '0'). I prepared this for teaching my students some very good C tricks. Thank you Bisqwit.

bidyutchakraborty
Автор

I love how his voice sounds like a computer. I like to imagine it's a computer teaching me about computers.

GenericInternetter
Автор

C was practically designed for obfuscation. Just use the define directive to replace all the keywords with random alphanumeric strings. You can do all kinds of meta programming to change the compiled binary as well.

mattr
Автор

While this is obfuscation, this is really for a specific kind of programming challenge called Code Golf where you try to write a program using a few characters as possible.

Some of my personal C/C++ code golf code:

Reads its own source file(named 'm') and prints out occurrences of characters in ascii order:
#include<set>
int main(){int a[256]{}, i;auto f=fopen("m", "r");while(i=~getc(f))a[~i]++;for(int x:a)x?printf("%c %d\n", i, x):0, ++i;}

Conway's Game of Life for the GBA using the tonc library (with identifier names shortened):
#include<tonc.h>
#define l
main(){R=1028;*P=32767;u8 x, y, s, m, p;for(;!(S=~K&1023););l M(x, y, Q()&1);for(;u8*v=(u8*)V;){F();l{for(m=-1, p=v[x+y*240], s=-p;++m<9;)s+=v[x+m%3-1+(y+m/3-1)*240];M(x, y, p?s<4&s>1:s==3);}}}

ScipiPurr