3
I would like to know the difference between PHP and PHP 64 Bits.
I was researching about the RealPerson.js
, where there was code for PHP and another for PHP 64 Bits:
PHP
function rpHash($value) {
$hash = 5381;
$value = strtoupper($value);
for($i = 0; $i < strlen($value); $i++) {
$hash = (($hash << 5) + $hash) + ord(substr($value, $i));
}
return $hash;
}
if (rpHash($_POST['realPerson'].salt) == $_POST['realPersonHash']) {
// Accepted
PHP 64bit
function rpHash($value) {
$hash = 5381;
$value = strtoupper($value);
for($i = 0; $i < strlen($value); $i++) {
$hash = (leftShift32($hash, 5) + $hash) + ord(substr($value, $i));
}
return $hash;
}
// Perform a 32bit left shift
function leftShift32($number, $steps) {
// convert to binary (string)
$binary = decbin($number);
// left-pad with 0's if necessary
$binary = str_pad($binary, 32, "0", STR_PAD_LEFT);
// left shift manually
$binary = $binary.str_repeat("0", $steps);
// get the last 32 bits
$binary = substr($binary, strlen($binary) - 32);
// if it's a positive number return it
// otherwise return the 2's complement
return ($binary{0} == "0" ? bindec($binary) :
-(pow(2, 31) - bindec(substr($binary, 1))));
}
if (rpHash($_POST['realPerson'].salt) == $_POST['realPersonHash']) {
// Accepted
Great explanation, I understand perfectly! Thank you for clarifying this for me!!!
– Willian Tártaro