Advertisement
voodooKobra

Quick64 (insecure hash function)

Jun 25th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2. // I needed a quick 64-bit hash function for PHP 5.4.x for a non-cryptographic purpose,
  3. // so I just mixed md4 and md5 (which are both thought to be secure) to get what I wanted
  4. function quick64($input, $raw_output=false) {
  5.   $hash = hash('md5', $input, true) ^ hash('md4', $input, true);
  6.   if($raw_output) {
  7.     return hex2bin(substr( bin2hex($hash), 8, 16));
  8.   } else {
  9.     return substr( bin2hex($hash), 8, 16);
  10.   }
  11. }
  12. /* Usage:
  13.   quick64($input); // Quick hex hash
  14.   quick64($input, 1); // Quick binary hash
  15. */
  16. # TESTING FUNCTION
  17. for($i = 0; $i < 32; $i++) {
  18.   $j = str_repeat('a', $i);
  19.   echo str_pad($j, 32, ' ', STR_PAD_LEFT)."\t".quick64($j)."\n";
  20. }
  21. # OUTPUT:
  22.                                     5e6a5b355ebc504f
  23.                                a    dd1288ee159d9c19
  24.                               aa    3f8ce95bdf38ab41
  25.                              aaa    f824e54e0497b7b2
  26.                             aaaa    15de74f8ddcc56f9
  27.                            aaaaa    fab5c420ad4f40e6
  28.                           aaaaaa    02ac1089839c6479
  29.                          aaaaaaa    6728193ab2c2171c
  30.                         aaaaaaaa    08a043e87d932e0d
  31.                        aaaaaaaaa    6a0e36a0752609ce
  32.                       aaaaaaaaaa    532c379aa12f300c
  33.                      aaaaaaaaaaa    e83cbdece9fd2d5b
  34.                     aaaaaaaaaaaa    78fb8db510ae9961
  35.                    aaaaaaaaaaaaa    ed603991464c4b87
  36.                   aaaaaaaaaaaaaa    c69794d565bd1f89
  37.                  aaaaaaaaaaaaaaa    1bb356a83fbde039
  38.                 aaaaaaaaaaaaaaaa    6b3361be021750cd
  39.                aaaaaaaaaaaaaaaaa    65155d86f62b9795
  40.               aaaaaaaaaaaaaaaaaa    69054b90519c1476
  41.              aaaaaaaaaaaaaaaaaaa    66bdbde7d4392c73
  42.             aaaaaaaaaaaaaaaaaaaa    babd1ccbb5cf1230
  43.            aaaaaaaaaaaaaaaaaaaaa    23b398b4444be296
  44.           aaaaaaaaaaaaaaaaaaaaaa    2aaf21e8d031de3c
  45.          aaaaaaaaaaaaaaaaaaaaaaa    30161c6004c1735e
  46.         aaaaaaaaaaaaaaaaaaaaaaaa    ad6d695db6a950cb
  47.        aaaaaaaaaaaaaaaaaaaaaaaaa    bb670fa603c7093c
  48.       aaaaaaaaaaaaaaaaaaaaaaaaaa    2023a087d5d5eb5d
  49.      aaaaaaaaaaaaaaaaaaaaaaaaaaa    384021e51e1061f2
  50.     aaaaaaaaaaaaaaaaaaaaaaaaaaaa    d036a2ef778a9b69
  51.    aaaaaaaaaaaaaaaaaaaaaaaaaaaaa    34cdf07316a0d641
  52.   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa    c6a1a7629a28819c
  53.  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa    aaf9ec412e7fea26
  54.  
  55. Good enough for me. Thought it might be worth sharing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement