当前位置:Gxlcms > PHP教程 > php5数字型字符串简易加解密的实现代码

php5数字型字符串简易加解密的实现代码

时间:2021-07-01 10:21:17 帮助过:4人阅读

一段可以对数字型字符串进行简单的加密与解密的代码,有需要的朋友,可以参考下。

代码如下:

replaceenc['/'.$i.'/'] = $this->replacement{$i}; 
$this->replacedec['/'.$this->replacement{$i}.'/'] = $i; 
} 
} 

public function encrypt($str) { 
return preg_replace( 
array_keys($this->replaceenc), 
$this->replaceenc, 
$this->mynotin(preg_replace("/(.)(.)/", "${2}$软件HR", $str)) 
); 
} 

public function decrypt($str) { 
return preg_replace("/(.)(.)/", "${2}$软件HR", 
$this->mynotout(preg_replace(array_keys($this->replacedec),$this->replacedec,$str)) 
); 
} 

private function mynotin($str) { 
$str_out = ""; 
$i = 0; 
while(isset($str{7*$i})) { 
$str_out .= (($this->prefix.substr($str, $i*7, 7))+0)^$this->match; 
$i++; 
} 
return $str_out; 
} 

private function mynotout($str) { 
$str_out = ""; 
$i = 0; 
while(isset($str{8*$i})) { 
$str_out .= substr((substr($str, $i*8, 8)+0)^$this->match, 1); 
$i++; 
} 
return $str_out; 
} 
} 
?>

人气教程排行