PHP的MD5加密解密函数

function encode($code,$seed = "qh8.net", $safe = false){
        if ($safe) $code = base64_encode(strrev(str_rot13($code)));
        $c_l = strlen($code);
        $s_m = md5($seed);
        $s_l = strlen($m);
        $a=0;
        while ($a <$c_l){
            $str .= sprintf ("%'02s",@base_convert(ord($code{$a})+ord($s_m{$s_l % $a+1}),10,32));
            $a++;
        }
        return $str;//wordwrap($str, 80, "n", true)
    }
   
   
    function decode($code, $seed = 'qh8.net', $safe = false){
        //$code = preg_replace("'[ rnt]+'", '', $code);
        preg_match_all("/.{2}/", $code, $arr);
        $arr = $arr[0];
        $s_m = md5($seed);
        $s_l = strlen($m);
        $a = 0;
        foreach ($arr as $value){
            $str .= @chr(@base_convert($value,32,10)-ord($s_m{$s_l % $a+1}));
            $a++;
        }
        if ($safe) $str = str_rot13(strrev(base64_decode($str)));
        return $str;
    }


posted @ 2011-03-18 14:38  SEC.VIP_网络安全服务  阅读(403)  评论(0编辑  收藏  举报