PHP实现的QQ空间g_tk加密算法
本文实例讲述了PHP实现的QQ空间g_tk加密算法。分享给大家供大家参考。具体如下:
//G_tk计算
functiongetGTK($skey){
$hash=5381;
for($i=0;$i<strlen($skey);++$i){
$hash+=($hash<<5)+utf8_unicode($skey[$i]);
}
return$hash&0x7fffffff;
}
functionutf8_unicode($c){
switch(strlen($c)){
case1:
returnord($c);
case2:
$n=(ord($c[0])&0x3f)<<6;
$n+=ord($c[1])&0x3f;
return$n;
case3:
$n=(ord($c[0])&0x1f)<<12;
$n+=(ord($c[1])&0x3f)<<6;
$n+=ord($c[2])&0x3f;
return$n;
case4:
$n=(ord($c[0])&0x0f)<<18;
$n+=(ord($c[1])&0x3f)<<12;
$n+=(ord($c[2])&0x3f)<<6;
$n+=ord($c[3])&0x3f;
return$n;
}
}
希望本文所述对大家的php程序设计有所帮助。