Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // I needed a quick 64-bit hash function for PHP 5.4.x for a non-cryptographic purpose,
- // so I just mixed md4 and md5 (which are both thought to be secure) to get what I wanted
- function quick64($input, $raw_output=false) {
- $hash = hash('md5', $input, true) ^ hash('md4', $input, true);
- if($raw_output) {
- return hex2bin(substr( bin2hex($hash), 8, 16));
- } else {
- return substr( bin2hex($hash), 8, 16);
- }
- }
- /* Usage:
- quick64($input); // Quick hex hash
- quick64($input, 1); // Quick binary hash
- */
- # TESTING FUNCTION
- for($i = 0; $i < 32; $i++) {
- $j = str_repeat('a', $i);
- echo str_pad($j, 32, ' ', STR_PAD_LEFT)."\t".quick64($j)."\n";
- }
- # OUTPUT:
- 5e6a5b355ebc504f
- a dd1288ee159d9c19
- aa 3f8ce95bdf38ab41
- aaa f824e54e0497b7b2
- aaaa 15de74f8ddcc56f9
- aaaaa fab5c420ad4f40e6
- aaaaaa 02ac1089839c6479
- aaaaaaa 6728193ab2c2171c
- aaaaaaaa 08a043e87d932e0d
- aaaaaaaaa 6a0e36a0752609ce
- aaaaaaaaaa 532c379aa12f300c
- aaaaaaaaaaa e83cbdece9fd2d5b
- aaaaaaaaaaaa 78fb8db510ae9961
- aaaaaaaaaaaaa ed603991464c4b87
- aaaaaaaaaaaaaa c69794d565bd1f89
- aaaaaaaaaaaaaaa 1bb356a83fbde039
- aaaaaaaaaaaaaaaa 6b3361be021750cd
- aaaaaaaaaaaaaaaaa 65155d86f62b9795
- aaaaaaaaaaaaaaaaaa 69054b90519c1476
- aaaaaaaaaaaaaaaaaaa 66bdbde7d4392c73
- aaaaaaaaaaaaaaaaaaaa babd1ccbb5cf1230
- aaaaaaaaaaaaaaaaaaaaa 23b398b4444be296
- aaaaaaaaaaaaaaaaaaaaaa 2aaf21e8d031de3c
- aaaaaaaaaaaaaaaaaaaaaaa 30161c6004c1735e
- aaaaaaaaaaaaaaaaaaaaaaaa ad6d695db6a950cb
- aaaaaaaaaaaaaaaaaaaaaaaaa bb670fa603c7093c
- aaaaaaaaaaaaaaaaaaaaaaaaaa 2023a087d5d5eb5d
- aaaaaaaaaaaaaaaaaaaaaaaaaaa 384021e51e1061f2
- aaaaaaaaaaaaaaaaaaaaaaaaaaaa d036a2ef778a9b69
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaa 34cdf07316a0d641
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa c6a1a7629a28819c
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaf9ec412e7fea26
- Good enough for me. Thought it might be worth sharing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement