当前位置:首页 > PHP教程 > php高级应用 > 列表

php自定加密与解密程序

发布:smiling 来源: PHP粉丝网  添加日期:2014-09-09 16:06:15 浏览: 评论:0 

PHP3 Cryption是一个非常容易被破解,不安全的加密功能,不应该是非常重要的东西用,虽然加密是好的,它不会阻碍对尖端开裂程序的严格考验.

不过,试试吧...这是一个伟大的方式来加密和解密字符串。与许多隐窝功能,这是双向的。基于一个密码,您可以加密或解密。您也可以解密或加密过无数次,通过循环或其他方法。字母表中的字符也是变化的。所有这些事情让你修改和巩固加密。

关于这最佳的部分?您可以加密与解密或一张纸和一支铅笔一块。这需要相当长一点,但你并不需要一台电脑是附近使用它,如果你曾经失去的代码,如果你还记得你的技术可以解密。

我写在约一小时这些功能,经过几次不成功的和令人沮丧的尝试,并获得了更长的时间我没有出路的。成功的那天后的最佳方式做它突然实现。

请注意,这不会加密/解密无形字符(空格),如换行符(n)或标签(吨)!很抱歉,但我尝试,如果你找到一个办法,请让我知道!

  1. * / 
  2. highlight_file(“crypto.php”); 
  3.  
  4. $ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !,.:;?~@#$%^&*()_+-=][}{/><"'";  
  5. $alphabet = $ralphabet . $ralphabet; 
  6.  
  7.  
  8. class Crypto { 
  9.  
  10. function encrypt ($password,$strtoencrypt) { 
  11.  
  12. global $ralphabet;  
  13. global $alphabet; 
  14.  
  15. for( $i=0; $i<strlen($password); $i++ )  
  16. {  
  17. $cur_pswd_ltr = substr($password,$i,1);  
  18. $pos_alpha_ary[] = substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet));  
  19. } 
  20.  
  21. $i=0;  
  22. $n = 0;  
  23. $nn = strlen($password);  
  24. $c = strlen($strtoencrypt); 
  25.  
  26. while($i<$c)  
  27. {  
  28. $encrypted_string .= substr($pos_alpha_ary[$n],strpos($ralphabet,substr($strtoencrypt,$i,1)),1); 
  29.  
  30. $n++;  
  31. if($n==$nn) $n = 0;  
  32. $i++;  
  33. } 
  34.  
  35. return $encrypted_string; 
  36.  
  37. } 
  38.  
  39.  
  40.  
  41.  
  42. function decrypt ($password,$strtodecrypt) { 
  43.  
  44. global $ralphabet;  
  45. global $alphabet; 
  46.  
  47. for( $i=0; $i<strlen($password); $i++ )  
  48. {  
  49. $cur_pswd_ltr = substr($password,$i,1);  
  50. $pos_alpha_ary[] = substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet));  
  51. } 
  52.  
  53. $i=0;  
  54. $n = 0;  
  55. $nn = strlen($password);  
  56. $c = strlen($strtodecrypt); 
  57.  
  58. while($i<$c)  
  59. {  
  60. $decrypted_string .= substr($ralphabet,strpos($pos_alpha_ary[$n],substr($strtodecrypt,$i,1)),1); 
  61.  
  62. $n++;  
  63. if($n==$nn) $n = 0;  
  64. $i++;  
  65. } 
  66.  
  67. return $decrypted_string; 
  68.  
  69.  
  70. } 
  71.  
  72.  
  73. function cryption_table ($password) { 
  74.  
  75. global $ralphabet;  
  76. global $alphabet; 
  77.  
  78. for( $i=0; $i<strlen($password); $i++ )  
  79. {  
  80. $cur_pswd_ltr = substr($password,$i,1);  
  81. $pos_alpha_ary[] = substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet));  
  82. } 
  83.  
  84.  
  85. print "<table border=1 cellpadding="0" cellspacing="0">n"; 
  86.  
  87. print "<tr><td></td>";  
  88. for( $j=0; $j<strlen($ralphabet); $j++ )  
  89. {  
  90. print "<td align="center"><font size="2" face="arial">" . substr($ralphabet,$j,1) . "</td>n";  
  91. }  
  92. print "</tr>"; 
  93.  
  94.  
  95. for( $i=0; $i<count($pos_alpha_ary); $i++ )  
  96. {  
  97. print "<tr><td align="right"><font size="2"><b>" . ($i+1) . "|</b></font></td>";  
  98. for( $k=0; $k<strlen($pos_alpha_ary[$i]); $k++ )  
  99. {  
  100. print "<td align="center"><font size="2" face="arial">" . substr($pos_alpha_ary[$i],$k,1) . "</td>n";  
  101. }  
  102. print "</tr>";  
  103. } 
  104.  
  105. print "</table>n"; 
  106.  
  107. } 
  108.  
  109. } // end class Crypto 
  110.  
  111. // Example written by Macro Zeng  
  112. // 网络技术主管座右铭:三人行其必有我师焉。http://www.phpfensi.com 
  113. $ct = new Crypto;  
  114. //$ct->cryption_table($password);  
  115. echo "<form action=$PHP_SELF method=post>";  
  116. if ($mod == 2) {  
  117. $strtodecrypt = $ct->encrypt ($password,$strtoencrypt);  
  118. echo 'Encrypted String(加密后的字段): ';  
  119. echo "<input type=text name=strtodecrypt size=45 value=$strtodecrypt> 
  120. ";  
  121. echo "密码锁: <input type=text name=password size=6 value=$password>";  
  122. echo "<input type=submit value="Decrypt(解密)">";  
  123. }  
  124. else {  
  125. $strtoencrypt = $ct->decrypt ($password,$strtodecrypt);  
  126. echo 'String to Encrypt(需要加密的字段): ';  
  127. echo "<input type=text name=strtoencrypt size=45 value=$strtoencrypt>//开源代码phpfensi.com 
  128. ";  
  129. echo "密码锁: <input type=text name=password size=6 value=$password>";  
  130. echo "<input type=submit value="Encrypt(加密)">";  
  131. echo "<input type=hidden name=mod value=2>";  
  132. }  
  133. echo "</form>";

Tags: php自定加密 php解密程序

分享到: