PHP Developers Network

DevNetwork Obfuscated PHP Contest 2006
Page 1 of 6

Author:  onion2k [ Wed Aug 09, 2006 3:13 am ]
Post subject:  DevNetwork Obfuscated PHP Contest 2006

Inspired by we are having an "obfuscated PHP" competition!

Obfuscated PHP:

Obfuscation is the art of making something very difficult to read. Obfuscated code is code that isn't immediately obvious to the reader what it's supposed to do. Obfuscated PHP is code written in PHP that you could look at, read, digest, and still only know what it does by running it. This isn't the same as "bad code". Obfuscated code has to be written very carefully otherwise it probably won't work.

The Contest:

Write a PHP script that will output a string backwards. The string will be passed as a _GET variable. The code must be as non-obvious as possible. It should be pretty much impossible to deduce the purpose of the script just by looking at it.

The Podium:

There are 3 winners;

3rd place - The Avrial Lavigne "Complicated!" award for the most complicated solution.
2nd place - The Kylie Minogue "Short like a tiny pixie!" award for the shortest solution.
1st place - The Jennifer Love Hewitt "OMG that's frickin' beautiful!" award for the most elegant solution.

The Rules:

1. Your code must be your own.
2. Your code must run in your own webspace so we can see it working.
3. Your code must only be ordinary PHP (Zend Optimizer is cheating).
4. Your code must be made available (duh, it's a code contest).
5. You should be able to explain how your code works in case we can't figure it out.
6. The judge's decision will be final (I'm the judge for now, might change later if people are actually interested in this).
7. All entries should be submitted as a reply to this thread in the form of a link to your script online somewhere and the source code (wrapped in
Syntax: [ Download ] [ Hide ]
tags, obviously).

8. Closing date is September 9th 2006. You've got 1 month.


1. Think out of the box.

2. Try writing code that generates new code.

3. Eval() is your friend.

4. So is create_function().

Author: [ Wed Aug 09, 2006 9:36 am ]
Post subject: 

Alright, I gave it a shot. It could've went any direction, so I wasn't sure what to do with it.


For some silly reason i wrote this assuming the string would be alphabetic only. This was actually kind of tough! I don't feel like redoing it at the moment, so we'll assume it will be an alpha string.

Assumes PHP >= 5 (str_split usage)


Syntax: [ Download ] [ Hide ]
function gobble_gook($str,$rand)
    $ret = array();
    $lt = range('a','z');
    $n = explode($rand,$str);
    foreach($n AS $nn)
        $ret[] = $lt[$nn];
    return $ret;
function more_gobble_gook($arr)
    $lt = range('a','z');
    foreach($arr AS $l)
        $ret[] = implode('',array_keys($lt,$l));
    return $ret;
$randstr    = str_replace(range(0,10),'',substr(sha1(uniqid(1)),0,rand(10,15)));
$val        = chr(115).chr(116).chr(114).chr(105).chr(110).chr(103);
$var        = eval("return '\$_'.strtoupper(implode('',gobble_gook('6'.\$randstr.'4'.\$randstr.'19',\$randstr)));");
$var        = $var.'[\''.eval("return \$val;").'\']';
$var        = eval("return $var;");
$var        = implode('',array_reverse(gobble_gook(implode($randstr,more_gobble_gook(str_split($var))),$randstr)));
echo $var;

How it works:

Firstly, a random string is generated and stripped of numbers to provide a value to explode with.
The $_GET variable name (string) is then determined with a series of chr()s.
Then "$_GET" is determined by 6-4-19 .. the position of the letters G-E-T in the alphabet, and passing them to gobble_gook() which then returns an array of the corresponding letter by exploding on the $randstr value.
That gives us "$_GET['string']" which is then eval()'d to the value of $_GET['string'].
Then we pass the value to more_gobble_gook() which returns the numeric position of each letter in the value in the alphabet.
Then, we pass this back to gobble_gook() which returns an array of every letter of the value as a single element.
Finally, we reverse that array using array_reverse() and implode it so it's a string.
Done. The string is then echo'd.

Confuse anyone else? OK, me too! Obfuscationsdlfkaon is hard: 8O

Author:  jayshields [ Wed Aug 09, 2006 12:11 pm ]
Post subject: 

Shortest solution award is covered anyway...
Syntax: [ Download ] [ Hide ]
if(isset($_GET['string']) && !empty($_GET['string'])) echo strrev($_GET['string']);

or just
Syntax: [ Download ] [ Hide ]
echo strrev($_GET['string']);

Anyway, my real answer is:
Syntax: [ Download ] [ Hide ]
function ui565kj5k4j65($a, $b, $c, $d, $e) {
    if($e == (($d * $c) / $b) + $a) {
        return eval("return '$'.chr(95).'G'.chr(69).'T';");
if((str_word_count(ui565kj5k4j65(2, 20, 4, 5, 3)) * 89000) == (2400221254 - 2400132254)) {
    $f = 'gni6rts';
    for($i=0; $i <= substr($f, 3, 1); $i++) {
        $f .= $f{(substr($f, 3, 1)+1)-$i};
    $g = html_entity_decode(eval("return ui565kj5k4j65(2, 20, 4, 5, 3).'[\''.substr($f, 7, 3).substr($f, 11).'g'.'\']';"));
    $h = eval("return $g;");
    $x = 0;
    while(TRUE && isset($h) && !empty($h)) {
        $h .= $h{(strlen($h)-($x*2))-1};
        if($x == (strlen($h)-$x)) break;
    echo substr($h, strlen($h)/2);

Test URL: (turns out it doesn't work, lol, cos it's not a PHP5 server maybe. I don't have a PHP5 server available except my home machine that I developed it on, but my IP changes every so often. If you're lucky enough to catch it on this IP, the URL is ).

That took me the best part of 2 hours, lol.

Author:  feyd [ Wed Aug 09, 2006 12:14 pm ]
Post subject: 

Author:  DrTom [ Wed Aug 09, 2006 12:21 pm ]
Post subject: 

Well, here's the solution I came up with.. Not overly obfuscated but yeah

and the code
Syntax: [ Download ] [ Hide ]
if(strlen($_GET['string']) < 1)

I kinda trimmed it up so that it fits i nthe forums but thats my answer

oh How it works
It generates an eval(echo(strrev(string)));
Not too complicated

Author:  jayshields [ Wed Aug 09, 2006 12:22 pm ]
Post subject: 

Author:  feyd [ Wed Aug 09, 2006 12:40 pm ]
Post subject: 

We are the observers, jay.

Author:  Chris Corbyn [ Wed Aug 09, 2006 12:52 pm ]
Post subject: 

Syntax: [ Download ] [ Hide ]
<?php eval(base64_decode('JHJlbD0nRSA9IG0qY14yJzskYW5zPT'.
'Lic7Jyk7fQ==')); ?>

Good luck!!

EDIT | You run it as http://foo/script.php?q=word

feyd | had to break the string apart to fit our pages.

Author:  Jenk [ Wed Aug 09, 2006 1:44 pm ]
Post subject: 

one liners ftw.. though I've split it to fit pages.. btw - run at your own risk, and you'll need to set execution time really, really high.

Syntax: [ Download ] [ Hide ]
<?php $a='c';$b='y';$c='3';$d='R';${base64_decode(($x=$a).($z=$c).($w=$d).($y=$b))}=
for ($i = 0; $i < 5;$i++){

Author:  RobertGonzalez [ Wed Aug 09, 2006 2:05 pm ]
Post subject: 

Syntax: [ Download ] [ Hide ]
$s = ( isset($_GET['s']) ) ? $_GET['s'] : ''; $sd = ( isset($_GET['s']) ); $sc = strlen($s); $sn = ''; $se = ''; $y = $sc - 1;
while ($y >= 0) { $sn .= $s{$y}; $y -=1; }
if ($sd) $se = $sn; echo $se;

Live at . If nothing is passed to it, it returns a blank screen. If ?s=somestring is passed to it, it reverses it.

EDIT | Modified to make it smaller. Now it is 218 Bytes.

Author:  hawleyjr [ Wed Aug 09, 2006 3:23 pm ]
Post subject: 

Author:  onion2k [ Wed Aug 09, 2006 3:25 pm ]
Post subject: 

Author:  RobertGonzalez [ Wed Aug 09, 2006 3:27 pm ]
Post subject: 

That is freaking awesome. I am so stealing that idea.

Author:  infolock [ Wed Aug 09, 2006 3:28 pm ]
Post subject: 

Syntax: [ Download ] [ Hide ]
echo z73a($_GET['string']);
function z73a($j) {
  $b1    = strlen('$x=0;$x+');
  $hw    = strlen($j);
  for($x = 0; $x < $hw; $x++) $eax0d .= str_pad(decbin(ord($j{$x})), $b1, '0', STR_PAD_LEFT);
  if(strlen($eax0d)%$b1) return false;
  $hw = strlen($eax0d);
  for($x=0; $x<$hw; $x += $b1) $o0 .= chr(bindec(substr($eax0d, $x, $b1)));
  return strrev($o0);

oops, live at :

Author:  jayshields [ Wed Aug 09, 2006 3:38 pm ]
Post subject: 

@hawley: I don't get it. Is this a variant of that brainf*ck language thing? I was gunna attempt something like that but it said pure PHP only. Your test page just shows a weird string. How do I reverse a string?

Page 1 of 6 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group