Web±à³Ì Readers Blog
create the blog for Web±à³Ì scholars
php¼ÓÃܽâÃܵĴúÂë
Submitted by ×÷Õß: admin
2008-06-18 16:33:12
php¼ÓÃܽâÃܵĴúÂë
| ÒÔÏÂÊÇ´úÂ룺 <?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ѧϰ |
Read more
ÔĶÁ (249)
ÆÀÂÛ (0)
·Ã¿Í ÆÀÂÛ
·¢±íÆÀÂÛ
Óû§µÇ¼
ÈÕÖ¾·ÖÀà©®Category
- ÍøÕ¾|PHPѧϰ [66]
- ÍøÕ¾|ASP±¸Íü [6]
- ÍøÕ¾|JSP½ø½× [3]
- ÍøÕ¾|Êý¾Ý¿âÀà [11]
- С̸|ддÐÄÇé [13]
- ÍøÕ¾|xmlѧϰ [0]
- ÍøÕ¾|Javascriptѧϰ [5]
- ÍøÕ¾|ÃæÏò¶ÔÏó [1]
- ÍøÕ¾|AJAXѧϰ [2]
- ÍøÕ¾|ÔÓÆßÔÓ°Ë [11]
- ÍøÕ¾|½¨Õ¾ÖªÊ¶Í¨µÀ [6]
- ÖÐÇï½Ú|´óÔÓ»° [11]
ÈȵãÎÄÕ©®Articles
- ÔÚTomcatÏÂJSP¡¢Se...
- ²ÉÓÃutf8±àÂë³¹µ×½...
- ÎҵĴóѧͬѧ»ØÒäÂ...
- ¸Ðл×î½üÔÚѧϰÉϰ...
- mysqlÊý¾Ý¿âµÄµ¼Èë...