-
2007-07-02
PHP 写的加密函数,支持私人密钥 - [网页制作]
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://chaochao.blogbus.com/logs/6272869.html
- <?php
- // 说明:PHP 写的加密函数,支持私人密钥
- function keyED($txt,$encrypt_key)
- {
- $encrypt_key = md5($encrypt_key);
- $ctr=0;
- $tmp = "";
- for ($i=0;$i<strlen($txt);$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<strlen($txt);$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<strlen($txt);$i++)
- {
- $md5 = substr($txt,$i,1);
- $i++;
- $tmp.= (substr($txt,$i,1) ^ $md5);
- }
- return $tmp;
- }
- $key = http://www.jiaoshihr.com.cn/;
- $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 <Br> ";
- print "解密的 text : $dec_text <Br> ";
- ?>
随机文章:
用 PHP 生成条形码 2007-07-02FCKeditor 的配置和使用方法 2007-06-13生成加水印的图片类 2007-06-12CSS语法基础:伪类——动态链接 2006-09-11利用条件注释制作下拉菜单 2006-09-11
收藏到:Del.icio.us
<< 用 PHP 生成条形码 | 首页 |







