Lectrician Posted April 20, 2009 Share Posted April 20, 2009 The below code is taken from my perl forums code. The code decloaks a formsession string sent as a hidden form element. It works fine to verify the form in Perl, but when I try to convert it to PHP I get errors conflicting outputs which are coming from the two lines below: $key = hex($hexkey); (PERL) $key = dechex($hexkey); (PHP) or $key = bin2hex($hexkey); (PHP) The Perl line above gives a different result to the PHP line(s). I have managed to convert down to this line from the top. Any help in figuring out why the perls HEX command varies from the PHP DECHEX command would be great! Also any pointers in converting from there downwards! (I know perls LENGTH is PHP STRLEN, and can sort the for loop). Thanks in advance for any help! $input = $_POST["formsession"]; if ($input !~ /\A[0-9A-F]+\Z/) {return $input; } # probably a non cloacked ID as it contains non hex code $input =~ s~0$~~; $hexkey = substr($input,length($input)-2,2); $key = hex($hexkey); for($n=0; $n < length($input)-2; $n += 2) { $dec = substr($input, $n, 2); $ascii = hex($dec) ^ $key; # xor it to reverse it $ascii = chr($ascii); $user .= $ascii; return $user; Quote Link to comment https://forums.phpfreaks.com/topic/154875-perl-to-php-conversion-help/ Share on other sites More sharing options...
DarkSuperHero Posted April 20, 2009 Share Posted April 20, 2009 i think you might be needing hexdec() - http://us.php.net/manual/en/function.hexdec.php .... PS- Maybe not... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/154875-perl-to-php-conversion-help/#findComment-814696 Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 What does a $hexkey look like that doesn't work and what does perl / php output it as please? Quote Link to comment https://forums.phpfreaks.com/topic/154875-perl-to-php-conversion-help/#findComment-814704 Share on other sites More sharing options...
Lectrician Posted April 21, 2009 Author Share Posted April 21, 2009 The input is something like this "6D5F470C7844490C785E4D48495F60494F585E454F454D422C" It is a couple of the boards systemwide variables cloaked into hex code. (that is hex code isn't it?). The code above should decloak this into binary which would reveal the systemwide variables. Quote Link to comment https://forums.phpfreaks.com/topic/154875-perl-to-php-conversion-help/#findComment-815220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.