<?php
function jspassword($p, $vc, $vt) {
$p = strtoupper(md5($p));
for ($i = 0; $i < strlen($p); $i = $i + 2) {
$temp .= '\x' . substr($p, $i, 2);
}
return strtoupper(md5(strtoupper(md5(hex2asc($temp) . hex2asc($vt))) . $vc));
}
function hex2asc($str) {
$str = join('', explode('\x', $str));
for ($i = 0;$i < strlen($str);$i += 2) {
$data.= chr(hexdec(substr($str, $i, 2)));
}
return $data;
}
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;
}
}
function get_g_tk($skey){
if(!$skey) return false;
$hash = 5381;
for($i=0;$i<strlen($skey);++$i){
$hash += ($hash << 5) + ord($skey[$i]);
}
return $hash & 0x7fffffff;
}
echo jspassword('password','!DZW','\x00\x00\x00\x00\xa2\xfc\x7a\x80')."\n";
echo getGTK("@gmj2sEfSM")."\n";
?
标签:none