龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP基于md5生成短HASH的代码

时间:2014-06-27 02:19来源:网络整理 作者:网络 点击:
分享到:
PHP基于md5生成短HASH的代码 ```{.php}/********** CHash provides users with a fairly strong but short hash for identification* Based on MD5**********/class stdHash{var $hashIn = #39;#39;;function __construct($hashIn=#39;
/*********
* CHash provides users with a fairly strong but short hash for identification
* Based on MD5
**********/
class stdHash{
    var $hashIn = '';
    function __construct($hashIn=''){
        $this->hashIn = $hashIn;
    }
    function hash($string){
        $cherryTable = Array('0'=>0,'1'=>1,'2'=>2,'3'=>3,'4'=>4,'5'=>5,'6'=>6,'7'=>7,'8'=>8,'9'=>9,'A'=>10,'B'=>11,'C'=>12,'D'=>13,'E'=>14,'F'=>15);
        $md = md5($string.$this->hashIn);$m="";
        for($i=0;$i<16;$i++){
            $m.=chr($cherryTable[$md[$i*2]]*16 + $cherryTable[$md[$i*2+1]]);
        }
        return preg_replace('~[N=]~','',str_rot13(base64_encode($m)));
    }
}

精彩图集

赞助商链接