fork download
  1. <?php
  2.  
  3. function PBKDF1($pass, $salt, $count, $cb)
  4. {
  5. static $base;
  6. static $extra;
  7. static $extracount= 0;
  8. static $hashno;
  9. static $state = 0;
  10.  
  11. if ($state == 0)
  12. {
  13. $hashno = 0;
  14. $state = 1;
  15.  
  16. $key = $pass . $salt;
  17. $base = sha1($key, true);
  18. for($i = 2; $i < $count; $i++)
  19. {
  20. $base = sha1($base, true);
  21. }
  22. }
  23.  
  24. $result = "";
  25.  
  26. if ($extracount > 0)
  27. {
  28. $rlen = strlen($extra) - $extracount;
  29. if ($rlen >= $cb)
  30. {
  31. $result = substr($extra, $extracount, $cb);
  32. if ($rlen > $cb)
  33. {
  34. $extracount += $cb;
  35. }
  36. else
  37. {
  38. $extra = null;
  39. $extracount = 0;
  40. }
  41. return $result;
  42. }
  43. $result = substr($extra, $rlen, $rlen);
  44. }
  45.  
  46. $current = "";
  47. $clen = 0;
  48. $remain = $cb - strlen($result);
  49. while ($remain > $clen)
  50. {
  51. if ($hashno == 0)
  52. {
  53. $current = sha1($base, true);
  54. }
  55. else if ($hashno < 1000)
  56. {
  57. $n = sprintf("%d", $hashno);
  58. $tmp = $n . $base;
  59. $current .= sha1($tmp, true);
  60. }
  61. $hashno++;
  62. $clen = strlen($current);
  63. }
  64.  
  65. // $current now holds at least as many bytes as we need
  66. $result .= substr($current, 0, $remain);
  67.  
  68. // Save any left over bytes for any future requests
  69. if ($clen > $remain)
  70. {
  71. $extra = $current;
  72. $extracount = $remain;
  73. }
  74.  
  75. return $result;
  76. }
  77.  
  78. var_dump(bin2hex(PBKDF1("System", "G:MFX62rlABW:IUYAX(i", 100, 24)));
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
string(48) "ee4d8bd9734dec177876713c1b8a2e3fe5ca25b829b1ef98"