<?php
header("Content-type: text/html; charset=utf-8");
include_once '/var/www/html/api/com/com_inc.php';
class HashUtil {
const s_M = 251;
public static function cal($_data, $len) {
Log::info("HashUtil::cal", Log::INFO);
try {
$_data = FuncUtil::chrToByts($_data, 0, $len);
$_h = 0;
$_a = 31415;
$_b = 27183;
for ($i = 0; $i < $len; $i++) {
$_val = $_data[$i];
//echo $_val . " ";
if ($_val >= 128) {
$_val = $_val - 256;
}
$_h = ($_a * $_h + $_val) % self::s_M;
$_a = $_a * $_b % (self::s_M-1);
}
return ($_h < 0) ? ($_h + self::s_M):$_h;
} catch (Exception $e) {
Log::info("UTCToChr Exception: " . $e->getMessage(), Log::EXCEPT);
}
}
}
?>