Пример #1
0
/**
 * Tests a string against a shash value
 *
 * @access  public
 * @param   string    the string to test
 * @param   string    the shash to test against
 * @param   int       the seed value to use
 * @param   callback  the hashing function to use
 * @return  bool
 */
function test_shash($str, $shash, $seed = null, $hash_alg = null)
{
    // Parse any shash meta data
    if (strpos($shash, SHASH_MAIN_DELIM) !== false) {
        $shash = explode(SHASH_MAIN_DELIM, $shash);
        if (count($shash) !== 3) {
            return false;
        }
        // Seperate out the meta data
        $shash_meta = $shash[1];
        $shash = $shash[2];
        // Parse the meta data
        $shash_meta = explode(SHASH_SUB_DELIM, $shash_meta);
        if (count($shash_meta) !== 2) {
            return false;
        }
        $hash_alg = $shash_meta[0];
        $seed = (int) $shash_meta[1];
    }
    // Check that we have all the needed data
    if (!$seed || !$hash_alg || !(@function_exists($hash_alg) || is_callable($hash_alg))) {
        return false;
    }
    // Check that the values match
    $test_shash = shash($str, $seed, $hash_alg, false);
    return $shash === $test_shash;
}
Пример #2
0
function hashMap($map)
{
    $width = strlen($map['map'][0]);
    $cells = rtrim(strtr(implode($map['map']), ['_' => 0, 'x' => 1]), '0');
    return shash($width . '.' . $cells);
}