Home > Backend Development > PHP Tutorial > QQ space g_tk encryption algorithm implemented by PHP, g_tk encryption algorithm_PHP tutorial

QQ space g_tk encryption algorithm implemented by PHP, g_tk encryption algorithm_PHP tutorial

WBOY
Release: 2016-07-13 09:46:53
Original
1045 people have browsed it

QQ space g_tk encryption algorithm implemented by PHP, g_tk encryption algorithm

This article describes the QQ space g_tk encryption algorithm implemented by PHP. Share it with everyone for your reference. The details are as follows:

//G_tk计算
function getGTK($skey){
  $hash = 5381;
  for($i=0;$i<strlen($skey);++$i){
   $hash += ($hash << 5) + utf8_unicode($skey[$i]);
  }
  return $hash & 0x7fffffff;
}
function utf8_unicode($c) {
  switch(strlen($c)) {
    case 1:
    return ord($c);
    case 2:
    $n = (ord($c[0]) & 0x3f) << 6;
    $n += ord($c[1]) & 0x3f;
    return $n;
    case 3:
    $n = (ord($c[0]) & 0x1f) << 12;
    $n += (ord($c[1]) & 0x3f) << 6;
    $n += ord($c[2]) & 0x3f;
    return $n;
    case 4:
    $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;
  }
}

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1029586.htmlTechArticleQQ space g_tk encryption algorithm implemented by PHP, g_tk encryption algorithm This article describes the QQ space g_tk encryption algorithm implemented by PHP . Share it with everyone for your reference. The details are as follows: //G_tk calculates fun...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template