crypt.inc.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. $encrypt_key = md5(rand(0,32000));
  19. $ctr=0;
  20. $tmp = "";
  21. for ($i=0;$i<strlen($txt);$i++)
  22. {
  23. if ($ctr==strlen($encrypt_key)) $ctr=0;
  24. $tmp.= substr($encrypt_key,$ctr,1) .
  25. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  26. $ctr++;
  27. }
  28. return base64_encode($this->keyED($tmp,$key));
  29. }
  30. function Decrypt($txt,$key)
  31. {
  32. $txt = $this->keyED(base64_decode($txt),$key);
  33. $tmp = "";
  34. for ($i=0;$i<strlen($txt);$i++){
  35. $md5 = substr($txt,$i,1);
  36. $i++;
  37. $tmp.= (substr($txt,$i,1) ^ $md5);
  38. }
  39. return $tmp;
  40. }
  41. function RandPass()
  42. {
  43. $randomPassword = "";
  44. for($i=0;$i<8;$i++)
  45. {
  46. $randnumber = rand(48,120);
  47. while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
  48. {
  49. $randnumber = rand(48,120);
  50. }
  51. $randomPassword .= chr($randnumber);
  52. }
  53. return $randomPassword;
  54. }
  55. }