protected function truncate($hash)
	{
		$truncated_hash = 0;
		$offset = ord(substr($hash, -1)) & 0xF;

		// Truncate hash using supplied sha1 hash
		for ($i = 0; $i < 4; ++$i)
		{
			$truncated_hash <<= 8;
			$truncated_hash  |= ord($hash[$offset + $i]);
		}

		// Truncate to a smaller number of digits.
		$truncated_hash &= 0x7FFFFFFF;
		$truncated_hash %= self::VERIFICATION_CODE_MODULUS;

		return $truncated_hash;
	}
protected function truncate($hash)
	{
		$truncated_hash = 0;
		$offset = ord(substr($hash, -1)) & 0xF;

		// Truncate hash using supplied sha1 hash
		for ($i = 0; $i < 4; ++$i)
		{
			$truncated_hash <<= 8;
			$truncated_hash  |= ord($hash[$offset + $i]);
		}

		// Truncate to a smaller number of digits.
		$truncated_hash &= 0x7FFFFFFF;
		$truncated_hash %= self::VERIFICATION_CODE_MODULUS;

		return $truncated_hash;
	}
protected function truncate ( $ hash ) { $ truncated_hash = 0 ; $ offset = ord ( substr ( $ hash , - 1 ) ) & 0xF ; // Truncate hash using supplied sha1 hash for ( $ i = 0 ; $ i < 4 ; ++ $ i ) { $ truncated_hash <<= 8 ; $ truncated_hash |= ord ( $ hash [ $ offset + $ i ] ) ; } // Truncate to a smaller number of digits. $ truncated_hash &= 0x7FFFFFFF ; $ truncated_hash %= self :: VERIFICATION_CODE_MODULUS ; return $ truncated_hash ; }
Truncate HMAC hash to binary for generating a TOTP code

@param string $hash HMAC hash

@return int Truncated binary hash
Truncate HMAC hash to binary for generating a TOTP code