建站极客
网络编程 PHP编程 正文
php5数字型字符串加解密代码
所属分类:
网络编程 / PHP编程
阅读数:
1486
收藏 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利用Mysql锁解决高并发的方法 这篇文章主要介绍了PHP利用Mysql锁解决高并发的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
php 后端实现JWT认证方法示例 这篇文章主要介绍了php 后端实现JWT认证方法示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
PHP命名空间与自动加载类详解 这篇文章主要介绍了PHP命名空间与自动加载类,结合实例形式详细分析了php自动加载类与命名空间原理、使用方法及相关操作注意事项,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP时间处理类操作示例 这篇文章主要介绍了PHP时间处理类,结合实例形式分析了DateTime、DateTimeZone、DateInterval及DatePeriod等常用日期时间处理类简单操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
利用PHP扩展Xhprof分析项目性能实践教程 XHProf是Facebook开发的性能调试工具,能帮助直观的统计显示PHP程序执行中各方法函数调用次数和消耗时间,以方便我们排查性能瓶颈并进行调优。下面这篇文章主要给大家介绍了关于利用PHP扩展Xhprof分析项目性能实践的相关资料,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP使用pdo实现事务处理操作示例 这篇文章主要介绍了PHP使用pdo实现事务处理操作,结合实例形式较为详细的分析了php基于pdo实现事务处理的相关原理与操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多