Hacker News new | ask | show | jobs
by packetpirate 2667 days ago
Fucking black magic obfuscation. Is it possible to learn this power?

I want to see someone try to rewrite C++'s entire syntax in the form of another language (I just have to assume it has already been done.)

3 comments

I'm no expert, but in this case there are a few strategic definitions that help a lot to both conserve space and obfuscate:

  #define r return
  #define l(a, b, c, d) for (i y = a; y < b; y++) for (int x = c; x < d; x++)
  typedef int i;
My goal was less to obfuscate than it was to compress the code. I kept it as clear as I could within the limits of trying to get the code really small. There weren't any deliberate obfuscations like using misleading variable names.

The "l" macro cut the code down significantly and is one of the tricks I'm most proud of.

"r" and "i" aren't that impactful in terms of length. Their main benefit is that they make it easier to split the code where I need to in order to render the big ASCII art "@" sign. That's a lot harder when you have multiple-letter identifiers that can't be split in the middle.

you may enjoy this article, where the author of a really clever bit of obfuscated C breaks down everything the code is doing.

https://www.a1k0n.net/2011/07/20/donut-math.html

The maze generator at http://tromp.github.io/pearls.html#maze is similarly accompanied by a link to a book chapter documenting the obfuscation.
There are a lot of examples to read through here: http://ioccc.org

C is used rather than C++, because C++ is a car crash before you even start trying to obfuscate.