PageRenderTime 65ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/concrete/libraries/3rdparty/adodb/session/crypt.inc.php

https://bitbucket.org/seanom/concrete5
PHP | 161 lines | 112 code | 48 blank | 1 comment | 20 complexity | 4dad264ca0f5f669be480305f6be8835 MD5 | raw file
  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. class SHA1Crypt{
  59. function keyED($txt,$encrypt_key)
  60. {
  61. $encrypt_key = sha1($encrypt_key);
  62. $ctr=0;
  63. $tmp = "";
  64. for ($i=0;$i<strlen($txt);$i++){
  65. if ($ctr==strlen($encrypt_key)) $ctr=0;
  66. $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
  67. $ctr++;
  68. }
  69. return $tmp;
  70. }
  71. function Encrypt($txt,$key)
  72. {
  73. srand((double)microtime()*1000000);
  74. $encrypt_key = sha1(rand(0,32000));
  75. $ctr=0;
  76. $tmp = "";
  77. for ($i=0;$i<strlen($txt);$i++)
  78. {
  79. if ($ctr==strlen($encrypt_key)) $ctr=0;
  80. $tmp.= substr($encrypt_key,$ctr,1) .
  81. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  82. $ctr++;
  83. }
  84. return base64_encode($this->keyED($tmp,$key));
  85. }
  86. function Decrypt($txt,$key)
  87. {
  88. $txt = $this->keyED(base64_decode($txt),$key);
  89. $tmp = "";
  90. for ($i=0;$i<strlen($txt);$i++){
  91. $sha1 = substr($txt,$i,1);
  92. $i++;
  93. $tmp.= (substr($txt,$i,1) ^ $sha1);
  94. }
  95. return $tmp;
  96. }
  97. function RandPass()
  98. {
  99. $randomPassword = "";
  100. srand((double)microtime()*1000000);
  101. for($i=0;$i<8;$i++)
  102. {
  103. $randnumber = rand(48,120);
  104. while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
  105. {
  106. $randnumber = rand(48,120);
  107. }
  108. $randomPassword .= chr($randnumber);
  109. }
  110. return $randomPassword;
  111. }
  112. }
  113. ?>