php专区

 首页 > php专区 > PHP应用 > 常用功能 > 一段php加密解密的代码-PHP实例

一段php加密解密的代码-PHP实例

分享到:
【字体:
导读:
          一段php加密解密的代码,lt;?phpnbsp;nbsp;$key=quot;Thisissupposedtobeasecretkey!!!quot;;nbsp;nbsp;functionkeyED$txt,$encrypt_keynbsp;nbsp;{nbsp;nbsp;$encrypt_key=md5$encrypt_key;nbsp;nbsp;$ctr=0;nbsp;nbsp;$tmp=quot;quot;;nbsp;nbsp;for...

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

$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
n";  
print "Encrypted text : $enc_text
n";  
print "Decrypted text : $dec_text
n";  
?>  

分享到:
一个程序下载的管理程序(一)-PHP实例
该程序的一些功能有几点: 1:完整的搜索引擎 2:三种排序对象.(加入时间,下载次数,程序名字).及两种排序方法(倒序,顺序). 3:管理员随时修改. 4:报告链接错误.供管理员随时修正. 5:分页功能. 创建表: CREATE TABLE download (    author varchar(15),    title varchar(30),    url varchar(200),    s...
消息持续发送的完整例子-PHP实例
测试过的环境   win2000/IIS linux/apache win2000 下的 apache 没有成功!不知道为什么!!!   
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……