Continued with chash:
[core.git] / contrib / chash / lib / functions.php
index c56cd6f06662bd31ca384a498aed54274918d324..c4a9433b22ec3de9a6f7f0aa1a07e6bb59c7757c 100644 (file)
@@ -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;
 }