Hi i'm trying to convert a php function in ruby language. Is there an error because the results are different The function in php language is:
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;
}
The function that i tried to make in ruby is:
def real_person_hash value
hash = 5381
value = value.to_s.upcase
for i in 0..(value.length - 1)
hash = ((hash << 5) + hash) + value[i]
end
hash
end
Es.
value = "nzxs"
php function returns:
2089377688
ruby function :
6384344984
I've also noted that the values of the first 3 for cycles are equal. and only in the last cycle the become different Why?