无聊的时候瞎写的,欢迎大虾们指正
common\ndv.php
/**
* ndv (not complete digital visa)
* 非完整数字签证
*
* +----------------------------------------------------+
* * ndv(基础函数库文件),属于ksef(kee simply efficient framework)项目扩展库函数
* @author kee
* @date 2012年12月10日
* @version alpha 1.0
* +----------------------------------------------------+
*/
class ndv{
private $str_list = array();
private $safestr = null;
private $bincode = null;
private $md5code = null;
private $sh1code = null;
private $safecode = null;
public function ndva($str, $mode = 'ndv'){
$this-> ndv_list($str);
$this-> ndv_safe_add();
$this-> ndv_4in1();
if($mode == 'ndv'){
//输出52位混合编码,默认选项
return $this-> safecode;
}elseif($mode == 'bin'){
//输出20位二进制校验码
return $this-> bincode;
}elseif($mode == 'md5'){
//输出32为md5校验码
return $this-> md5code;
}elseif($mode == 'sh1'){
//输出32位sh1校验码
return $this-> sh1code;
}
}
private function ndv_list($str) {
$str_len = strlen($str); //计算字符串长度
$str_arr = array(); //拆解字符串数组
$str_list = array(); //混序列表
// $mod3 = $str_len%3; //模3值
$len3 = intval($str_len / 3); //除3取整
$list = 0;
//进行一次循环,拆解字符串,混序排列
for ($i = 0, $x = 0; $i $str_arr[$x] = md5(md5(substr($str, $i, 3)) . md5($str)); //拆解字符串,取字符串摘要获取64位混合编码
//混序排列
$this->bincode .= $str_arr[$x] % 2;
if ($str_arr[$x] % 2 == 1) {
//如果模2值为1,则序列下沉
$str_list[$len3] = $str_arr[$x];
$len3--;
} elseif ($str_arr[$x] % 2 == 0) {
//如果模2值为0,则序列上浮
$str_list[$list] = $str_arr[$x];
$list++;
