crypt.inc.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  56. class SHA1Crypt{
  57. function keyED($txt,$encrypt_key)
  58. {
  59. $encrypt_key = sha1($encrypt_key);
  60. $ctr=0;
  61. $tmp = "";
  62. for ($i=0;$i<strlen($txt);$i++){
  63. if ($ctr==strlen($encrypt_key)) $ctr=0;
  64. $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
  65. $ctr++;
  66. }
  67. return $tmp;
  68. }
  69. function Encrypt($txt,$key)
  70. {
  71. $encrypt_key = sha1(rand(0,32000));
  72. $ctr=0;
  73. $tmp = "";
  74. for ($i=0;$i<strlen($txt);$i++)
  75. {
  76. if ($ctr==strlen($encrypt_key)) $ctr=0;
  77. $tmp.= substr($encrypt_key,$ctr,1) .
  78. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  79. $ctr++;
  80. }
  81. return base64_encode($this->keyED($tmp,$key));
  82. }
  83. function Decrypt($txt,$key)
  84. {
  85. $txt = $this->keyED(base64_decode($txt),$key);
  86. $tmp = "";
  87. for ($i=0;$i<strlen($txt);$i++){
  88. $sha1 = substr($txt,$i,1);
  89. $i++;
  90. $tmp.= (substr($txt,$i,1) ^ $sha1);
  91. }
  92. return $tmp;
  93. }
  94. function RandPass()
  95. {
  96. $randomPassword = "";
  97. for($i=0;$i<8;$i++)
  98. {
  99. $randnumber = rand(48,120);
  100. while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
  101. {
  102. $randnumber = rand(48,120);
  103. }
  104. $randomPassword .= chr($randnumber);
  105. }
  106. return $randomPassword;
  107. }
  108. }