PHP用skey计算QQ bkn
两种方法 BKN的用途很多,不多说了
第一种:
function bkn($skey){
$hash = 5381;
for ($i = 0, $len = strlen($skey);$i < $len; ++$i) {
$hash +=($hash << 5) + charCodeAt($skey, $i);
}
return $hash & 2147483647;
}
function charCodeAt($str, $index){
$char = mb_substr($str, $index, 1, 'UTF-8');
$value = null;
if (mb_check_encoding($char, 'UTF-8'))
{
$ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
$value = hexdec(bin2hex($ret));
}
return $value;
}
调用方法:bkn('@xxxxx')
第二种:
function Get_BKN($skey){
$len=strlen($skey);
$hash=5381;
for($i=0;$i<$len;$i++){
$hash+=((($hash<<5) & 0x7fffffff)+ord($skey[$i])) & 0x7fffffff;
$hash&=0x7fffffff;
}
return $hash & 0x7fffffff;
}
调用方法一样
- END -
文章链接:https://www.ityinhu.com/698.html
作者邮箱:ponyj@qq.com