Obfuscated C Rickroll
Code
Here is the code: rr.c
Spoiler Warning
It's already been spoiled in the title! It's really hard to have Rickrolls
because ideally they'd surprise people, but it you make it obscure enough
for that then people will never be able to discover them.
Requirements
This requires a terminal emulator that supports 24-bit ANSI colors.
These days most Linux terminal emulators do, including stock xterm
(at least on Debian).
There is sound too! On a Debian system at least if you have
/usr/bin/aplay
it will attempt to pipe the sound into it at the default 8kHz/8-bit unsigned.
If aplay is not detected it will write the sound to the file "r.raw"
which you can then try to play on your sound program of choice, or if
you have a SUN machine, cat it to /dev/audio.
Obfuscation
It was so hard to get this to fit in the size requirements that I stopped
obfuscating once I made it fit.
Attempts to make things look cooler or shrink things more only seemed
to make things bigger somehow, due to the complex size accounting rules
for the competition.
The graphics are RLE compressed and using a base-64 like variant.
The sound is two-channels using a very simple custom tracker-like format.
Though in the end each pattern is done once. Even though some patterns
repeat it would have taken more code than it would save to implement that
and there wasn't enough room!
Background
Hopefully it's obvious what this is. I wish I had more space, I could
have made it sneakier and also had a few more frames of animation.
It's about half animation, half music right now. I should have optimized
the music better. An additional frame of animation was 256 bytes but I had
to remove it to fix the music code.
Believe it or not this is actually a rough port of an
Atari 2600 version
of this program.
popen() drama
The code tries to popen() /usr/bin/aplay for sound, and you can pipe in
the raw sound data. I thought it would be nice to detect if that's not
available and create a file instead. But it turns out on Linux it's not
possible to get a file-not-found error with popen(). It can only really
tell if the shell fork failed, not if the exec() hit file-not-found.
I find the manpage misleading and am working on getting an update to
address this.
Back to my obfuscated C page