Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Totally Unintelligible Code (Takes Brains To Write)

DZone's Guide to

Totally Unintelligible Code (Takes Brains To Write)

· Web Dev Zone ·
Free Resource

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

By totally unintelligible, I mean this:

_=[]|[];$=_++;__=(_<<_);___=(_<<_)+_;____=__+__;_____=__+___;$$=({}+"")[_____]+
({}+"")[_]+({}[$]+"")[_]+(($!=$)+"")[___]+(($==$)+"")[$]+(($==$)+"")[_]+(($==$)
+"")[__]+({}+"")[_____]+(($==$)+"")[$]+({}+"")[_]+(($==$)+"")[_];$$$=(($!=$)+""
)[_]+(($!=$)+"")[__]+(($==$)+"")[___]+(($==$)+"")[_]+(($==$)+"")[$];$_$=({}+"")
[_____]+({}+"")[_]+({}+"")[_]+(($!=$)+"")[__]+({}+"")[__+_____]+({}+"")[_____]+
({}+"")[_]+({}[$]+"")[__]+(($==$)+"")[___]; ($)[$$][$$]($$$+"('"+$_$+"')")();

That's JavaScript, written by Yosuke Hasagawa (who is kind of insane..ly awesome). Without any alphanumeric characters. What does it do? Run it and see. (Won't mess anything up, promise.)

How does it work? Well, some quirks of JavaScript, activated by a UTF-8 geek's incredible patience. But you can do something similar in PHP, as Fredrik Nordberg Almroth did:

<?=($_=@$_GET[2]).@$_($_GET[1])?>

Okay, so there's a GET in there, which makes a little more sense. (Or not, in which case, see Fredrik's explanation.) But what about totally non-alphanumeric PHP?

Try this:

<?
$_="";
$_[+""]='';
$_="$_"."";
$_=($_[+""]|"").($_[+""]|"").($_[+""]^"");
?>
<?=${'_'.$_}['_'](${'_'.$_}['__']);?>

From this slick blogpost.

At this point you might (rightly) wonder why I'm posting more non-alphanumeric characters. It's just the wrong encoding, you'll say. True; but re-encoding code can help you push a language's boundaries just a tad..and these are as purely code as any cryptographer's problem, and yet actually execute in a real programming language you already know.

And if you want a more complete explanation, check out the follow-up to the last post cited, with full explanatory slides.

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}