PHP的加密和解密程序方法

来源:互联网 发布:充电监控软件 编辑:程序博客网 时间:2024/04/26 00:31
<script type="text/javascript"><!--google_ad_client = "pub-4490194096475053";/* 内容页,300x250,第一屏 */google_ad_slot = "3685991503";google_ad_width = 300;google_ad_height = 250;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  1. <?php 
  2. $key = "This is supposed to be a secret key !!!"
  3. function keyED($txt,$encrypt_key
  4. $encrypt_key = md5($encrypt_key); 
  5. $ctr=0; 
  6. $tmp = ""
  7. for ($i=0;$i<strlen($txt);$i++) 
  8. if ($ctr==strlen($encrypt_key)) $ctr=0; 
  9. $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); 
  10. $ctr++; 
  11. return $tmp
  12. function encrypt($txt,$key
  13. <script type="text/javascript"><!--google_ad_client = "pub-4490194096475053";/* 728x90, 创建于 08-12-8 */google_ad_slot = "0403648181";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  14. srand((double)microtime()*1000000); 
  15. $encrypt_key = md5(rand(0,32000)); 
  16. $ctr=0; 
  17. $tmp = ""
  18. for ($i=0;$i<strlen($txt);$i++) 
  19. if ($ctr==strlen($encrypt_key)) $ctr=0; 
  20. $tmp.= substr($encrypt_key,$ctr,1) . 
  21. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); 
  22. $ctr++; 
  23. return keyED($tmp,$key); 
  24. function decrypt($txt,$key
  25. $txt = keyED($txt,$key); 
  26. $tmp = ""
  27. for ($i=0;$i<strlen($txt);$i++) 
  28. $md5 = substr($txt,$i,1); 
  29. $i++; 
  30. $tmp.= (substr($txt,$i,1) ^ $md5); 
  31. return $tmp
  32. $string = "Hello World !!!"
  33. // encrypt $string, and store it in $enc_text 
  34. $enc_text = encrypt($string,$key); 
  35. // decrypt the encrypted text $enc_text, and store it in $dec_text 
  36. $dec_text = decrypt($enc_text,$key); 
  37. print "Original text : $string <Br>/n"
  38. print "Encrypted text : $enc_text <Br>/n"
  39. print "Decrypted text : $dec_text <Br>/n"
  40. ?> 
原创粉丝点击