日期:2014-05-17  浏览次数:20399 次

来看代码了!
无聊的时候瞎写的,欢迎大虾们指正

Common\NDV.php
/**
 * NDV (Not complete Digital Visa)
 * 非完整数字签证
 *
 * +----------------------------------------------------+
 * * NDV(基础函数库文件),属于KSEF(Kee Simply Efficient Framework)项目扩展库函数
 * @author Kee <chinboy2012@gmail.com>
 * @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_Len; $x++) {
      $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] =&n