Advertisement
uuuyyttu

Encrypt code Temp

Dec 9th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <HTML>
  2. <?php
  3. header("Content-Type:text/html; charset=utf-8");
  4. function encrypt($data, $key)
  5. {
  6. $key = md5($key);
  7. $x  = 0;
  8. $len = strlen($data);
  9. $l  = strlen($key);
  10. for ($i = 0; $i < $len; $i++)
  11. {
  12. if ($x == $l)
  13. {
  14. $x = 0;
  15. }
  16. $char .= $key{$x};
  17. $x++;
  18. }
  19. for ($i = 0; $i < $len; $i++)
  20. {
  21. $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
  22. }
  23. return base64_encode($str);
  24. }
  25.  
  26. /*function decrypt($data, $key)
  27. {
  28. $key = md5($key);
  29. $x = 0;
  30. $data = base64_decode($data);
  31. $len = strlen($data);
  32. $l = strlen($key);
  33. for ($i = 0; $i < $len; $i++)
  34. {
  35. if ($x == $l)
  36. {
  37. $x = 0;
  38. }
  39. $char .= substr($key, $x, 1);
  40. $x++;
  41. }
  42. for ($i = 0; $i < $len; $i++)
  43. {
  44. if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1)))
  45. {
  46. $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
  47. }
  48. else
  49. {
  50. $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
  51. }
  52. }
  53. return $str;
  54. }
  55. */
  56. //$data="測試";
  57. $key="111wwwq2";
  58. //$ans=encrypt($data,$key);
  59.  
  60. //echo $ans."<br />".decrypt($ans,$key);
  61. ?>
  62.  
  63.     <head><title>ACGN臨時頁面</title></head>
  64.     <body>
  65.         <?php
  66.         if (isset($_POST["done"])&&$_POST["done"]==1) {
  67.             if (isset($_POST["comment"])&&$_POST["comment"]!="") {
  68.                 echo '
  69.                 <center><h3>請將以下文字複製到FB上的回覆區,這樣我就能收到囉~</h3></center><br />
  70.                 ';
  71.                 $data=$_POST["comment"];
  72.                 $ans=encrypt($data,$key);
  73.                 echo $ans;
  74.                 $_POST["done"]=0;
  75.                 echo '<input type="button" value="按我寫第二題" onClick="window.location.reload()">';
  76.  
  77.         }
  78.     }
  79.  
  80.     //not answr section
  81.         else{
  82.             ?>
  83.  
  84.             <h3><center>請將您想出的題目打在下面的框框中<center></h3><br />
  85.             <form method="POST">
  86.             題目:<br /><textarea rows="4" cols="50" name="comment"></textarea>
  87.             <input type="submit" value="確定!">
  88.             <input type="hidden" name="done" value="1">
  89.             </form>
  90.  
  91.             <?php
  92.  
  93.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement