Pawn/php/javascript problem
#1

I need help with converting this to php:
pawn Код:
stock num_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}
I've tried:
PHP код:
function num_hash($string)
    {
        
$length strlen($string);
        
$s1 1;
        
$s2 0;
        for(
$n 0$n $length$n++)
        {
            
$s1 strval(($s1 $string[$n]) % 65521);
            
$s2 strval(($s2 $s1) % 65521);
        }
        echo (
$s2 << 16) + $s1;
    } 
But it does not return same value.
Reply
#2

bump
Reply
#3

Anyone?
Reply
#4

PHP код:
function num_hash($string)
    {
        
$length strlen($string);
        
$s1 1;
        
$s2 0;
        for(
$n 0$n $length$n++)
        {
            
$s1 = ($s1 ord($string[$n])) % 65521;
            
$s2 = ($s2 $s1) % 65521;
        }
        echo (
$s2 << 16) + $s1;
    } 
Reply
#5

Thanks man, that works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)