Hacker News new | ask | show | jobs
Obfuscating “Hello World” in Python (benkurtovic.com)
285 points by carljoseph 4201 days ago
10 comments

When I first saw the final code, I thought it unfathomable that I could resolve it down to "Hello World!" at any point in my lifetime. The following 20min provided an education into logic, programming, and Python that rivals 200 page reference books with clear explanations and the ideal amount of build up for each step. Thanks Ben for the post!
I thought this was a great post, some amazing code, and humbling since this is WAY beyond my current - and future - ability.

Even more impressive - it looks like the author is a freshman in college! https://www.linkedin.com/in/benkurtovic

Nice work, Ben!

Damn. If I was a freshman in his CS class I would hate his guts.
Can you explain why? I don't really understand this sentiment at all.
It's a human emotion called jealousy.
This is perhaps the clearest example on the value of implementation-oriented code comments. When you need them, they are superheroic. But... don't need them, please.
I barely know any Python and upon first glance I could easily get an idea of how it worked (without looking at the explanation): by computing the required strings out of funny-named variables with shifts and arithmetic. co_nlocals is obviously the only actual integer constant from which all the other values are coming from.

Only then did I read the explanation, and realised I wasn't far-off (the only thing I got wrong was the string computation, which I thought would be a string concatenation.) I think it says something about the language when even obfuscated code in it is rather readable! (Then again, I do RE where most of the code I'm reading is disassembled machine instructions, so maybe my perspective on what constitutes obfuscation is a bit skewed...)

"There should be one-- and preferably only one --obvious way to do it."
I don't think this counts as "obvious".

BTW my intuition say turing completness require that there are many ways to do it, for at least some values of "it", but I can't proove it.

Since turing completness implies that you can write an interpreter for any other programming language you can do it in python in at least as many ways as there are programming languages where you can do it.
I saw this yesterday and shared it with a friend who had introduced me to code golf. Simply fantastic, particularly the comments.
I didn't realize there needed to be an IOPCC but now I do.
This is like brainf*ck to me.
Brainfuck relies on pointer arithmetic, while this is using bit shifting.

Brainfuck commands: http://en.wikipedia.org/wiki/Brainfuck#Commands

Bit shifting: http://stackoverflow.com/a/141873/58740

the level of obfuscation is impressive. i wonder if similar obfuscation for javascript exists? The one from google doesn't seem to quite work right and end up breaking my script. The paid version from jscrambler seems to work but seems like a large waste of money to obfuscate one file.
This code is so ugly that I thought it was Lisp :p