PDA

View Full Version : [Help] Pawno ==> PHP


jimmyC
09/10/2011, 05:09 PM
Hello,

i need to convert one function from pawno to php, i tried to do it like this

Pawno code:

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;
}

PHP code:

function cryptpw($buf)

{

$length=strlen($buf);
$s1 = 1;
$s2 = 0;
$n;
for ($n=0; $n<$length; $n++) {
$s1 = ($s1 + $buf[$n]) % 65521;
$s2 = ($s2 + $s1) % 65521;
}

return ($s2 << 16) + $s1;

}


but it doesnt work, if someone knows how please tell me

Nero_3D
09/10/2011, 06:11 PM
here


function cryptpw($buf) {
return hash('adler32', $buf);
}

Just check that list (http://www.php.net/manual/en/function.hash-algos.php) (a bit down on the page) which hash functions are supported

jimmyC
09/10/2011, 08:09 PM
doesnt works

Nero_3D
10/10/2011, 04:55 PM
tested it, it seemed that the hash was converted to hex

Just convert it back :)

function cryptpw($buf) {
return hexdec(hash('adler32', $buf));
}

Have fun