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

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

* Script Name: encrypt.php

* Creation Date: 2008-4-7 10:36

* Last Modified: 2008-4-12 16:00

* Author: meyu

* Copyright (c) 2007

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

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

class Encryption {

/**

* 最终的密文代码,可设为任意不重复的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 

$this->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}${1}", $str))

);

}

public function decrypt($str) {

return preg_replace("/(.)(.)/", "${2}${1}",

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

}

}

?>

时间: 2008-04-21

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值