手机
当前位置:查字典教程网 >编程开发 >php教程 >php5数字型字符串加解密代码
php5数字型字符串加解密代码
摘要:

<?php

/*----------------------------------------------------------------------------

*ScriptName:encrypt.php

*CreationDate:2008-4-710:36

*LastModified:2008-4-1216:00

*Author:meyu

*Copyright(c)2007

*Purpose:数字字符串简易加解密

*----------------------------------------------------------------------------*/

classEncryption{

/**

*最终的密文代码,可设为任意不重复的10位英文字符a-zA-Z

*/

private$replacement='urskydMeIV';

/**

*增加的密文第一位,可设为1位除0以外的整数,即1-9

*/

private$prefix="8";

/**

*公钥,长度小于8位的正整数

*/

private$match="111111";

/**

*转换后对照数组

*/

private$replaceenc;

private$replacedec;

function__construct(){

for($i=0;$i<10;$i++){

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

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

}

}

publicfunctionencrypt($str){

returnpreg_replace(

array_keys($this->replaceenc),

$this->replaceenc,

$this->mynotin(preg_replace("/(.)(.)/","${2}${1}",$str))

);

}

publicfunctiondecrypt($str){

returnpreg_replace("/(.)(.)/","${2}${1}",

$this->mynotout(preg_replace(array_keys($this->replacedec),$this->replacedec,$str))

);

}

privatefunctionmynotin($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;

}

privatefunctionmynotout($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;

}

}

?>

【php5数字型字符串加解密代码】相关文章:

php解析字符串里所有URL地址的方法

php-fpm 启动参数及重要配置详解

php中file_exists函数使用详解

php支持中文字符串分割的函数

PHP生成指定随机字符串的简单实现方法

php生成图片验证码

php一个解析字符串排列数组的方法

php将字符串随机分割成不同长度数组的方法

php数据库备份脚本

PHP解密Unicode及Escape加密字符串

精品推荐
分类导航