亚洲VA成无码人在线观看天堂,久久久久亚洲av无码专区桃色,98色婷婷在线,成人吸奶大片在线观看

以文本方式查看主題

-  西安網(wǎng)站建設(shè)|西安網(wǎng)站制作|西安做網(wǎng)站_網(wǎng)站知識(shí)交流論壇  (http://www.ksblcw.cn/bbs/index.asp)
--  網(wǎng)絡(luò)編程學(xué)習(xí)  (http://www.ksblcw.cn/bbs/list.asp?boardid=5)
----  [分享]實(shí)現(xiàn)php加密/解密代碼  (http://www.ksblcw.cn/bbs/dispbbs.asp?boardid=5&id=154)

--  作者:longlong
--  發(fā)布時(shí)間:2010/1/4 12:56:55
--  [分享]實(shí)現(xiàn)php加密/解密代碼

php加密/解密代碼

 

php中怎么實(shí)現(xiàn)加密和怎么實(shí)現(xiàn)解密里。其實(shí)很簡(jiǎn)單。php有很多函數(shù)給大家用。今天就簡(jiǎn)單的寫(xiě)一段代碼給大家。代碼入邪 以下是代碼片段:
<?php
$key = "www.ksblcw.cn!!!";
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;
}

使用測(cè)試:
$string = "029900.com!!!";
//加密并把加密的值給$enc_text
$enc_text = encrypt($string,$key);
//解密并把加密的值給$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>";
?>