Dcrypt\Str::strcmp PHP Method

strcmp() private static method

Private constant-time strcmp method to use when hash_equals is unavailable.
private static strcmp ( string $knownHash, string $givenHash ) : boolean
$knownHash string Hash of the known string
$givenHash string Hash of the given string
return boolean true if the two strings are the same, false otherwise
    private static function strcmp($knownHash, $givenHash)
    {
        $result = 0;
        // XOR the bytes of the 2 input hashes and loop over them.
        // Each byte value is then added to a running total...
        foreach (\str_split($knownHash ^ $givenHash) as $xbyte) {
            $result += \ord($xbyte);
        }
        // Strings are equal if the final result is exactly zero
        return 0 === $result;
    }