建站极客
网络编程 PHP编程 正文
php5数字型字符串加解密代码
所属分类:
网络编程 / PHP编程
阅读数:
1509
收藏 0
赞 0
分享
<?php /* ---------------------------------------------------------------------------- * 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 < 10; $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; } } ?>
php实现在服务器端调整图片大小的方法 这篇文章主要介绍了php实现在服务器端调整图片大小的方法,实例分析了imageResizer与loadimage操作图片的相关技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php动态绑定变量的用法 这篇文章主要介绍了php动态绑定变量的用法,涉及php变量的判定与动态定义的相关技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php实现读取和写入tab分割的文件 这篇文章主要介绍了php实现读取和写入tab分割的文件,涉及php文件读写及字符串操作的相关技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php自动给网址加上链接的方法 这篇文章主要介绍了php自动给网址加上链接的方法,可实现对本文中的网址加上链接的功能,涉及正则匹配的相关技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php获取指定范围内最接近数的方法 这篇文章主要介绍了php获取指定范围内最接近数的方法,可实现根据给定区间长度划分各个区间,并在其中寻找与给定数最接近的数,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php使用ob_flush不能每隔一秒输出原理分析 这篇文章主要介绍了php使用ob_flush不能每隔一秒输出原理,较为详细的分析了php使用ob_flush的相关原理与Linux下使用cli方式的使用方法,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多