php5数字型字符串加解密代码

前端之家收集整理的这篇文章主要介绍了php5数字型字符串加解密代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<?PHP @H_4040@/*---------------------------------------------------------------------------- @H404_0@ScriptName:encrypt.PHP @H_404_0@CreationDate:2008-4-710:36 @H_4040@*LastModified:2008-4-1216:00 @H4040@*Author:meyu @H4040@*Copyright(c)2007 @H4040@*Purpose:数字字符串简易加解密 @H4040@----------------------------------------------------------------------------/ classEncryption{ @H4040@/** @H404_0@最终的密文代码,可设为任意不重复的10位英文字符a-zA-Z @H_404_0@/ @H_4040@private$replacement='urskydMeIV'; /** @H404_0@增加的密文第一位,可设为1位除0以外的整数,即1-9 @H_404_0@/ @H_4040@private$prefix="8"; /** @H4040@*公钥,长度小于8位的正整数 @H4040@*/ @H4040@private$match="111111"; /** @H4040@*转换后对照数组 @H4040@*/ @H4040@private$replaceenc; @H404_0@private$replacedec; function_construct(){ @H4040@for($i=0;$i<10;$i++){ @H4040@$this->replaceenc['/'.$i.'/']=$this->replacement{$i}; @H4040@$this->replacedec['/'.$this->replacement{$i}.'/']=$i; @H4040@} @H4040@} publicfunctionencrypt($str){ @H404_0@returnpregreplace( @H404_0@arraykeys($this->replaceenc),@H4040@$this->replaceenc,@H404_0@$this->mynotin(pregreplace("/(.)(.)/","${2}${1}",$str)) @H4040@); @H4040@} publicfunctiondecrypt($str){ @H404_0@returnpregreplace("/(.)(.)/",@H404_0@$this->mynotout(preg_replace(arraykeys($this->replacedec),$this->replacedec,$str)) @H4040@); @H4040@} privatefunctionmynotin($str){ @H404_0@$strout=""; @H4040@$i=0; @H4040@while(isset($str{7*$i})){ @H404_0@$strout.=(($this->prefix.substr($str,$i*7,7))+0)^$this->match; @H4040@$i++; @H4040@} @H404_0@return$strout; @H4040@} privatefunctionmynotout($str){ @H404_0@$strout=""; @H4040@$i=0; @H4040@while(isset($str{8*$i})){ @H404_0@$strout.=substr((substr($str,$i*8,8)+0)^$this->match,1); @H4040@$i++; @H4040@} @H404_0@return$strout; @H4040@} @H4040@} @H404_0@?>

猜你在找的PHP相关文章