crypt.inc.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>
  3. class MD5Crypt{
  4. function keyED($txt,$encrypt_key)
  5. {
  6. $encrypt_key = md5($encrypt_key);
  7. $ctr=0;
  8. $tmp = "";
  9. for ($i=0;$i<strlen($txt);$i++){
  10. if ($ctr==strlen($encrypt_key)) $ctr=0;
  11. $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
  12. $ctr++;
  13. }
  14. return $tmp;
  15. }
  16. function Encrypt($txt,$key)
  17. {
  18. srand((double)microtime()*1000000);
  19. $encrypt_key = md5(rand(0,32000));
  20. $ctr=0;
  21. $tmp = "";
  22. for ($i=0;$i<strlen($txt);$i++)
  23. {
  24. if ($ctr==strlen($encrypt_key)) $ctr=0;
  25. $tmp.= substr($encrypt_key,$ctr,1) .
  26. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  27. $ctr++;
  28. }
  29. return base64_encode($this->keyED($tmp,$key));
  30. }
  31. function Decrypt($txt,$key)
  32. {
  33. $txt = $this->keyED(base64_decode($txt),$key);
  34. $tmp = "";
  35. for ($i=0;$i<strlen($txt);$i++){
  36. $md5 = substr($txt,$i,1);
  37. $i++;
  38. $tmp.= (substr($txt,$i,1) ^ $md5);
  39. }
  40. return $tmp;
  41. }
  42. function RandPass()
  43. {
  44. $randomPassword = "";
  45. srand((double)microtime()*1000000);
  46. for($i=0;$i<8;$i++)
  47. {
  48. $randnumber = rand(48,120);
  49. while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
  50. {
  51. $randnumber = rand(48,120);
  52. }
  53. $randomPassword .= chr($randnumber);
  54. }
  55. return $randomPassword;
  56. }
  57. }
  58. ?>