Firstly, hope you did well in your exam 🙂
Secondly, I'm sorry I kind of forgot about this topic and got all dragged back by work.
Thirdly, I have to say it's much harder when you can't see the php (I liked that comment trick and the mixing up of the variable order) but this should work for most cases:
<?php
$content = file_get_contents('http://madwormer2.free.fr/ascii.php');
$content = str_replace(array("\r", "\n"), '', $content);
if(!preg_match('!'.preg_quote('<script type="text/javascript">function ').'(.+?)'.preg_quote('(emailaddress) {').'(.+?) = (-?[0-9]);(.+?) = (-?[0-9]);(.+?) = (-?[0-9]);(.+?) = (-?[0-9]);'.preg_quote(' for (i = 0; i <= emailaddress.length; i+=2) {').'( \s*/?/?.*\s*)'.preg_quote('document.write(String.fromCharCode((parseInt(((\'0x\') + emailaddress.substring(i,i+2)),16)) - (').'(-?[0-9]) (\+|-) (.+?) (\+|-) (.+?) (\+|-) (.+?) (\+|-) (.+?)'.preg_quote(')));}}</script>').'!', $content, $matches)){
echo 'Error: <br />'.$content;
exit;
}
//print_r($matches); exit;
$function = $matches[1];
unset($matches[10]);
$matches = array_values($matches);
$calc = array(0,0,0,0,0,0);
$calc[0] = $matches[11];
$calc[2] = $matches[13];
$calc[4] = $matches[15];
$calc[6] = $matches[17];
for($i=0; $i<4; $i++){
$num = (2 * $i) + 2;
$name = $matches[$num];
$value = $matches[$num+1];
if($name == $matches[12]){
$n = 1;
}else if($name == $matches[14]){
$n = 3;
}else if($name == $matches[16]){
$n = 5;
}else{
$n = 7;
}
$calc[$n] = '('.$value.')';
}
$calc = ' return ('.$matches[10].') '.implode(' ', $calc).'; ';
$num = eval($calc);
preg_match('!<script>'.$function.'\(\'(.+?)\'\);</script>!', $content, $match);
$data = $match[1];
echo $content.'<br /><br /><br />';
for($i=0; $i<strlen($data); $i+=2){
echo chr(hexdec($data[$i].$data[$i+1]) - $num);
}
?>
Basically it's breakable but I think it'd be easier to let a human do it 😃
Soon I'll post some code that's even harder to break but I don't have enough time to do all this again :p
Btw sorry for the rubbish code, I was trying to do this quickly