G_tk encryption algorithm and g_tk encryption algorithm in the QQ space implemented by PHP
This example describes the g_tk encryption algorithm of the QQ space implemented by PHP. Share it with you for your reference. The details are as follows:
// G_tk compute 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 ;}}
I hope this article will help you with php programming.