<?php

$pw_in = trim($_POST['pw']);

if (!empty($pw_in))
	$pw = decrypt($pw_in);


echo 
	'<form method="POST">'.
	'<input type="text" value="'.htmlspecialchars($pw_in).'" name="pw"/>'.
	'<input type="submit" value="de-obfuscate">'.
	'</form>';

if (!empty($pw) && $ret == 0) 
	echo '<p>cleartext is: <b>'.htmlspecialchars($pw).'</b></p>';


function decrypt($enc) 
{
	$xlat = array(
		0x64, 0x73, 0x66, 0x64, 0x3b, 0x6b, 0x66, 0x6f,
		0x41, 0x2c, 0x2e, 0x69, 0x79, 0x65, 0x77, 0x72,
		0x6b, 0x6c, 0x64, 0x4a, 0x4b, 0x44, 0x48, 0x53 , 0x55, 0x42
	);

	$seed = intval(substr($enc,0,2));
	if ($seed > 15)
		return NULL;

	$pw = '';
	for ($i=2; $i<=strlen($enc); $i+=2) {
		$s = strtolower(substr($enc, $i, 2));
		if (strlen($s) != 2)
			continue;
		$val = ord(pack("H*", $s));
		$pw .= chr($val ^ $xlat[$seed++]);
	}

	return $pw;
}


?>
