Jump to content

[help] Generate Hash Code


aisatriani

Recommended Posts

please help ..

I have a function the following hashgenerate

 

<?php

function HashCode($val)
{
$maxInt     = 4294967295;
$maxPostInt = 2147483647;
$h = 0;

$value = String_to_ASCII($val);
for($i=0;$i<count($value);$i++)
{
$h = $h*31 + $value[$i];
if($h > $maxInt){
    $div = intval($h/($maxInt + 1));
    $h = $h - ($div * ($maxInt + 1));
}
if($h > $maxPostInt){
    
    $h = $h - $maxInt - $i;

}
}
return $h;
}

function String_to_ASCII($string)
{
$ascii = NULL;
$value = array();
for($i=0;$i < strlen($string);$i++)
{
array_push($value,ord($string[$i]));
}
return $value;
}



}

echo HashCode("JYeHn8Tu5donkey"));

?>

from the above function to generate strings will produce

JYeHn8Tu5donkey = -5.52888247115E+022
hello = 99162322

 

and i want to generate these JYeHn8Tu5donkey to generate numbers -22635908

 

function what is wrong?

 

please guidance

Link to comment
https://forums.phpfreaks.com/topic/202069-help-generate-hash-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.