403_3@
PHP@H_
403_3@function encode_pass($tex,$key,$type="encode",$expiry=0){@H_
403_3@ $chrArr=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',@H_
403_3@ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',@H_
403_3@ '0','1','2','3','4','5','6','7','8','9');@H_
403_3@ if($type=="decode"){@H_
403_3@ if(strlen($tex)<14)return false;@H_
403_3@ $verity_str=substr($tex,8);@H_
403_3@ $tex=substr($tex,8);@H_
403_3@ if($verity_str!=substr(md5($tex),8)){@H_
403_3@ //完整性验证失败@H_
403_3@ return false;@H_
403_3@ } @H_
403_3@ }@H_
403_3@ $key_b=$type=="decode"?substr($tex,6):$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62]; $rand_key=$key_b.$key; @H_
403_3@ //设置时间选项@H_
403_3@ $modnum=0;$modCount=0;$modCountStr="";@H_
403_3@ if($expiry>0){@H_
403_3@ if($type=="decode"){@H_
403_3@ $modCountStr=substr($tex,6,1);@H_
403_3@ $modCount=$modCountStr=="a"?10:floor($modCountStr);@H_
403_3@ $modnum=substr($tex,7,$modCount);@H_
403_3@ $rand_key=$rand_key.(floor((time()-$modnum)/$expiry));@H_
403_3@ }else{@H_
403_3@ $modnum=time()%$expiry;@H_
403_3@ $modCount=strlen($modnum);@H_
403_3@ $modCountStr=$modCount==10?"a":$modCount; $rand_key=$rand_key.(floor(time()/$expiry)); @H_
403_3@ }@H_
403_3@ $tex=$type=="decode"?base64_decode(substr($tex,(7+$modCount))):"xugui".$tex;@H_
403_3@ }else{@H_
403_3@ $tex=$type=="decode"?base64_decode(substr($tex,6)):"xugui".$tex;@H_
403_3@ }@H_
403_3@ $rand_key=md5($rand_key);
@H_403_3@ $texlen=strlen($tex);@H_403_3@ $reslutstr="";@H_403_3@ for($i=0;$i<$texlen;$i++){@H_403_3@ $reslutstr.=$tex{$i}^$rand_key{$i%32};@H_403_3@ }@H_403_3@ if($type!="decode"){@H_403_3@ $reslutstr=trim(base64_encode($reslutstr),"==");@H_403_3@ $reslutstr=$modCount?$modCountStr.$modnum.$reslutstr:$reslutstr;@H_403_3@ $reslutstr=$key_b.$reslutstr;@H_403_3@ $reslutstr=substr(md5($reslutstr),8).$reslutstr;@H_403_3@ }else{@H_403_3@ if(substr($reslutstr,5)!="xugui"){@H_403_3@ return false;@H_403_3@ }@H_403_3@ $reslutstr=substr($reslutstr,5);@H_403_3@ }@H_403_3@ return $reslutstr;@H_403_3@}@H_403_3@$psa=encode_pass("woshi ceshi yong de ","taintainxousad","encode",120);@H_403_3@echo $psa;@H_403_3@echo "\r\n解密:";@H_403_3@echo encode_pass($psa,'decode',120);@H_403_3@?>@H_403_3@