最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 自定义加密解密实现代码
时间:2022-06-24 15:59:32 编辑:袖梨 来源:一聚教程网
| 代码如下 | 复制代码 |
|
php // 说明:PHP 写的加密函数,支持私人密钥 // 整理:https://www.111cn.net function keyED($txt,$encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr=0; $tmp = ""; for ($i=0;$i if ($ctr==strlen($encrypt_key)) $ctr=0; $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); $ctr++; } return $tmp; } function encrypt($txt,$key) { srand((double)microtime()*1000000); $encrypt_key = md5(rand(0,32000)); $ctr=0; $tmp = ""; for ($i=0;$i if ($ctr==strlen($encrypt_key)) $ctr=0; $tmp.= substr($encrypt_key,$ctr,1) . (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); $ctr++; } return keyED($tmp,$key); } function decrypt($txt,$key) { $txt = keyED($txt,$key); $tmp = ""; for ($i=0;$i $md5 = substr($txt,$i,1); $i++; $tmp.= (substr($txt,$i,1) ^ $md5); } return $tmp; } $key = "YITU.org"; $string = "我是加密字符"; // encrypt $string, and store it in $enc_text $enc_text = encrypt($string,$key); // decrypt the encrypted text $enc_text, and store it in $dec_text $dec_text = decrypt($enc_text,$key); print "加密的 text : $enc_text "; print "解密的 text : $dec_text "; ?> |
|
相关文章
- 燕云十六声听梅点雪怎么打 听梅点雪打法攻略 11-17
- 境界刀鸣黑崎一护刻印怎么选 黑崎一护刻印选择推荐 11-17
- 境界刀鸣浦原喜助技能是什么 浦原喜助技能详解 11-17
- 境界刀鸣石田雨龙技能是什么 石田雨龙技能详解 11-17
- 洛克王国世界极品宠物蛋怎么获取 极品宠物蛋获取攻略 11-17
- 明日方舟终末地能力值是什么 能力值介绍一览 11-17