Determines what shard the provided string should be on.

@param string $string String input use to determine shard.
@param int    $shards Size of shard pool.

@return int  Returns an integer between 0 and ($shards-1), i.e. 0-255
171777
public static function determineShard($string, int $shards = 256): int
    {
        // first 4 chars of md5 give us a 16 bit keyspace (0-65535)
        $num = hexdec(substr(md5((string)$string), 0, 4));
        return $num % $shards;
    }
1284864
public function hash(string $string): Hash {
        $hash = new Hash();
        $hash->setAlgorithm($this->getAlgorithm());
        $value = hash($this->getAlgorithm(), $string, true);
        $hash->setValue($value);
        return $hash;
    }
384618
public function bitsPerCharacter($string)
    {
        if (is_string($string) === false) {
            throw new \InvalidArgumentException('Argument must be a string.');
        }
        $sum = 0;
        $length = strlen($string);
        foreach (array_values(array_count_values(str_split($string))) as $count) {
            $freq = $count / $length;
            $sum += $freq * log($freq, 2);
        }
        return (int) ceil(- $sum);
    }
291998
public function ucFirst($string)
    {
        $first = $this->sub($string, 0, 1);
        $first = $this->upp($first);

        return $first . $this->sub($string, 1);
    }
1278974
protected static function indexOf($string, $char)
    {
        $pos = @strpos($string, $char);

        return false === $pos ? -1 : $pos;
    }
1156589
public static function createHash($string) {
		$salt = substr(str_replace('+', '.', base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 22);
		return crypt($string, '$2a$10$' . $salt . '$'); // we use Blowfish with a cost of 10
	}
316166
public function encryptWithUserSettings($string)
    {
        if (!$string) {
            return null;
        }

        // If the algorithm or salt is not available, it means we are operating
        // on legacy account with unhashed password. Do not hash the string.
        if (!$this->PasswordEncryption) {
            return $string;
        }

        // We assume we have PasswordEncryption and Salt available here.
        $e = PasswordEncryptor::create_for_algorithm($this->PasswordEncryption);

        return $e->encrypt($string, $this->Salt);
    }
65935
public function generateHmac($string)
    {
        if (!is_string($string)) {
            throw new InvalidArgumentForHashGenerationException('A hash can only be generated for a string, but "' . gettype($string) . '" was given.', 1255069587);
        }

        return hash_hmac('sha1', $string, $this->getEncryptionKey());
    }
347426
public function checkhash($string, $hashedString)
	{
		$verified = password_verify($string, $hashedString);
		if ( ! $verified) 
		{
			// Try the fallbacks
			foreach (static::$fallbacks as $algo => $fallback)
			{
				$verified = $fallback['function']($string, $hashedString, $fallback['options']);
				if ($verified) break;
			}
		}
		return $verified;
	}
494017
public function get_value($string)
    {
        // now just drop the msb and reorder it + parse it in own string
        $valuestring = '';
        $string_length = strlen($string);

        $i = 1;

        while ($string_length > $i)
        {
            // unset msb string and reorder it
            $valuestring = substr($string, $i, 7) . $valuestring;
            $i += 8;
        }

        // now interprete it
        return bindec($valuestring);
    }
1165520
static function fetchByHashString( $hashString )
    {
        $cond = array( 'hash_string' => $hashString );
        $return = eZPersistentObject::fetchObject( self::definition(), null, $cond );
        return $return;
    }
594571
public static function hashString($string, $iteration = 5)
    {
        $result = $string;

        for ($i = 0; $i < $iteration; $i++) {
            $result = md5($result);
        }

        return $result;
    }
1183591
public function parse($string) {
        $segments = $this->parseSegments($string);
        $segments = array_extend($segments, $this->parseHost(array_get($segments, 'host')));

        return $this->replaceEmptyStringsWithNull($segments);
    }
61273
public final function write($string): int
   {
       if (!$this->isWritable()) {
           throw new RuntimeException("Can't write: stream is not writable");
       }
       $this->meta["eof"] = true;
	   if (($size = (int) fwrite($this->stream, (string) $string))) {
		    $this->meta["size"] = $this->getMetadata("size") + $size;
	   }
       return $size;
   }
15199
protected function stringWidthWithoutFormatting(string $string): int
	{
		return (int) mb_strwidth($this->formatter !== null ? $this->formatter->stripTags($string) : $string);
	}
1303941
protected static function JsHash($String, $Secure = TRUE)
    {
        if ($Secure === TRUE)
            $Secure = 'md5';

        switch ($Secure) {
            case 'sha1':
                return sha1($String);
                break;
            case 'md5':
            case FALSE:
                return md5($String);
            default:
                return hash($Secure, $String);
        }
    }
562539
public static function stringToUnits($string)
    {
        new Money($string, new Currency('USD')); // TODO optimize?

        return (int)bcmul($string, '100', self::GAAP_PRECISION);
    }