网页功能: 加入收藏 设为首页 网站搜索  
一段php加密解密的代码
发表日期:2004-07-23作者:[转贴] 出处:  

<?php
$key = "This is supposed to be a secret key !!!";

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

$string = "Hello World !!!";

// 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 "Original text : $string <Br> ";
print "Encrypted text : $enc_text <Br> ";
print "Decrypted text : $dec_text <Br> ";
?>

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 一段php加密解密的代码
本类热点文章
  用PHP验证邮箱是否真实有效
  PHP5的变化与PHP6展望
  用户IP、浏览器、操作系统
  oracle资料库函式库
  oracle资料库函式库
  基于PHP的聊天室(二)
  基于PHP的聊天室(二)
  php调用mysql存储过程和函数的方法
  正则表达式在网络编程中的运用
  专家预言:PHP将比Java更受欢迎
  高效的中文字符串截取函数
  高效的中文字符串截取函数
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2024 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.01152