X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=contrib%2Fchash%2Flib%2Ffunctions.php;fp=contrib%2Fchash%2Flib%2Ffunctions.php;h=c4a9433b22ec3de9a6f7f0aa1a07e6bb59c7757c;hp=c56cd6f06662bd31ca384a498aed54274918d324;hb=05df7f70f0502385f1d80a027afa4792bfb372a9;hpb=6db13ced94b5846a4d0740bf323db3840b15ad5b diff --git a/contrib/chash/lib/functions.php b/contrib/chash/lib/functions.php index c56cd6f0..c4a9433b 100644 --- a/contrib/chash/lib/functions.php +++ b/contrib/chash/lib/functions.php @@ -43,15 +43,22 @@ function multipleHashString ($str) { */ function calculateSumFromHash ($hash) { // Everything starts with zero ... + //* NOISY-DEBUG: */ printf('[%s:%d]: hash(%d)=%s - CALLED!'. PHP_EOL, __FUNCTION__, __LINE__, strlen($hash), $hash); $sum = 0; + // Part of the hash is not decodeable + $decodeA = explode('$', $hash); + $decode = $decodeA[4]; + // Loop through hash - for ($idx = 0; $idx < (strlen($hash) / 2); $idx++) { + //* NOISY-DEBUG: */ printf('[%s:%d]: decode=%s' . PHP_EOL, __FUNCTION__, __LINE__, $decode); + for ($idx = 0; $idx < (strlen($decode) / 2); $idx++) { // And add it - $sum = $sum + hexdec(substr($hash, $idx, 2)); + $sum = $sum + hexdec(substr($decode, $idx, 2)); } // END - for // And return it + //* NOISY-DEBUG: */ printf('[%s:%d]: sum=%d - EXIT!' . PHP_EOL, __FUNCTION__, __LINE__, $sum); return $sum; }