Convert the given key (a simple Python object) to a unique-ish hash
    suitable for a filename.
338172
def make_filename_hash(key):
    
    key_repr = repr(key).replace(BASE_DIR, '').encode('utf8')
    # This is really stupid but necessary for making the repr()s be the same on
    # Python 2 and 3 and thus allowing the test suite to run on both.
    # TODO better solutions include: not using a repr, not embedding hashes in
    # the expected test results
    if sys.platform == 'win32':
        # this is to make sure the hash is the same on win and unix platforms
        key_repr = key_repr.replace(b'\\\\', b'/')
    key_repr = re.sub(b"\\bu'", b"'", key_repr)
    key_hash = hashlib.md5(key_repr).digest()
    return base64.b64encode(key_hash, b'__').decode('ascii').rstrip('=')
464214
def hash_key(self, key):
        
        for i, destination_key in enumerate(self._dict):
            if key < destination_key:
                return destination_key

        return key
1253007
def file_md5(self, file_name):
        """"""
        with open(file_name, "rb") as f:
            file_contents = f.read()
            file_hash = hashlib.md5(file_contents).hexdigest()
        return file_hash
852121
def hash( key, seed = 0x0 ):
    '''  '''

    key = bytearray( xencode(key) )

    def fmix( h ):
        h ^= h >> 16
        h  = ( h * 0x85ebca6b ) & 0xFFFFFFFF
        h ^= h >> 13
        h  = ( h * 0xc2b2ae35 ) & 0xFFFFFFFF
        h ^= h >> 16
        return h

    length = len( key )
    nblocks = int( length / 4 )

    h1 = seed

    c1 = 0xcc9e2d51
    c2 = 0x1b873593

    # body
    for block_start in xrange( 0, nblocks * 4, 4 ):
        # ??? big endian?
        k1 = key[ block_start + 3 ] << 24 | \
             key[ block_start + 2 ] << 16 | \
             key[ block_start + 1 ] <<  8 | \
             key[ block_start + 0 ]
             
        k1 = ( c1 * k1 ) & 0xFFFFFFFF
        k1 = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
        k1 = ( c2 * k1 ) & 0xFFFFFFFF
        
        h1 ^= k1
        h1  = ( h1 << 13 | h1 >> 19 ) & 0xFFFFFFFF # inlined ROTL32
        h1  = ( h1 * 5 + 0xe6546b64 ) & 0xFFFFFFFF

    # tail
    tail_index = nblocks * 4
    k1 = 0
    tail_size = length & 3

    if tail_size >= 3:
        k1 ^= key[ tail_index + 2 ] << 16
    if tail_size >= 2:
        k1 ^= key[ tail_index + 1 ] << 8
    if tail_size >= 1:
        k1 ^= key[ tail_index + 0 ]
    
    if tail_size > 0:
        k1  = ( k1 * c1 ) & 0xFFFFFFFF
        k1  = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
        k1  = ( k1 * c2 ) & 0xFFFFFFFF
        h1 ^= k1

    #finalization
    unsigned_val = fmix( h1 ^ length )
    if unsigned_val & 0x80000000 == 0:
        return unsigned_val
    else:
        return -( (unsigned_val ^ 0xFFFFFFFF) + 1 )
419585
def _gen_key(self, key):
        
        b_key = self._md5_digest(key)
        return self._hashi(b_key, lambda x: x)
247002
def hashed(source_filename, prepared_options, thumbnail_extension, **kwargs):
    
    parts = ':'.join([source_filename] + prepared_options)
    short_sha = hashlib.sha1(parts.encode('utf-8')).digest()
    short_hash = base64.urlsafe_b64encode(short_sha[:9]).decode('utf-8')
    return '.'.join([short_hash, thumbnail_extension])
80950
def calculate_hash_for_file(name):
    '''
    
    '''
    longlongformat = 'q'  # long long
    bytesize = struct.calcsize(longlongformat)

    f = open(name, "rb")

    filesize = os.path.getsize(name)
    hash = filesize

    minimum_size = 65536 * 2
    assert filesize >= minimum_size, \
        'Movie {name} must have at least {min} bytes'.format(min=minimum_size,
                                                             name=name)

    for x in range(65536//bytesize):
        buffer = f.read(bytesize)
        (l_value,)= struct.unpack(longlongformat, buffer)
        hash += l_value
        hash = hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number


    f.seek(max(0,filesize-65536),0)
    for x in range(65536//bytesize):
        buffer = f.read(bytesize)
        (l_value,)= struct.unpack(longlongformat, buffer)
        hash += l_value
        hash = hash & 0xFFFFFFFFFFFFFFFF

    f.close()
    returnedhash = "%016x" % hash
    return returnedhash
371088
private function key_to_hash($key)
    {
        if (null === $key) {
            $hash = 'null';

        } else if (is_int($key)) {
            $hash = $key;

        } else if (is_float($key)) {
            $hash = "f_$key";

        } else if (is_bool($key)) {
            $hash = "b_$key";

        } else if (is_string($key)) {
            $hash = "s_$key";

        } else if (is_object($key) || is_callable($key)) {
            $hash = spl_object_hash($key);

        } else if (is_array($key)) {
            $hash = 'a_' . md5(json_encode($key));

        } else if (is_resource($key)) {
            $hash = "r_$key";

        } else {
            throw new \InvalidArgumentException(sprintf(
                'Unsupported key type "%s"',
                gettype($key)
            ));
        }

        $this->map_hash_to_key[$hash] = $key;
        return $hash;
     }
298407
def hash(filepath, method='sha1', buffer_size=65536):
    
    if method == 'sha1':
        hash_function = hashlib.sha1()
    elif method == 'md5':
        hash_function = hashlib.md5()
    else:
        raise NotImplementedError('Only md5 and sha1 hashes are known, but '
                                  ' \'{}\' was specified.'.format(method))

    with open(filepath, 'rb') as fp:
        while True:
            data = fp.read(buffer_size)
            if not data:
                break
            hash_function.update(data)
    return hash_function.hexdigest()
1227084
def _convert_key_to_str(key):
    '''
    
    '''
    # IMPORTANT: on PY2, the secret key must be str and not unicode to work
    # properly with hmac.new (see http://bugs.python.org/issue5285)
    #
    # pylint: disable=incompatible-py3-code,undefined-variable
    return salt.utils.data.encode(key) \
        if six.PY2 and isinstance(key, unicode) \
        else key
1293781
def get_hash(key: str) -> int:
    
    # 4294967295 == 2**32 - 1 which is the maximum allowable seed for a `numpy.random.RandomState`.
    return int(hashlib.sha1(key.encode('utf8')).hexdigest(), 16) % 4294967295
751576
def hash_of_file(path):
    """"""
    with open(path, 'rb') as archive:
        sha = sha256()
        while True:
            data = archive.read(2 ** 20)
            if not data:
                break
            sha.update(data)
    return encoded_hash(sha)
853484
private String getFilenameForKey(String key) {
        int firstHalfLength = key.length() / 2;
        String localFilename = String.valueOf(key.substring(0, firstHalfLength).hashCode());
        localFilename += String.valueOf(key.substring(firstHalfLength).hashCode());
        return localFilename;
    }
136171
def _gen_md5_filehash(fname, *args):
    '''
    
    '''
    _hash = hashlib.md5()
    with salt.utils.files.fopen(fname, 'rb') as f:
        for chunk in iter(lambda: f.read(4096), b''):
            _hash.update(chunk)

    for extra_arg in args:
        _hash.update(six.b(str(extra_arg)))
    return _hash.hexdigest()
1216087
function hmac(key, string, encoding) {
  return crypto.createHmac('sha256', key).update(string, 'utf8').digest(encoding)
}
1334653
def sha_hash_file(filename):
    
    hash_sha = hashlib.sha1()

    with open(filename, 'rb') as f:
        for chunk in iter(lambda: f.read(1024*1024), b""):
            hash_sha.update(chunk)

    return hash_sha.hexdigest()
478214
def to_hash
            index_hash = Hash.new
            index_hash["json_claz"] = self.class.name
            index_hash["id"] = id
            index_hash["name"] = name
            index_hash["org_id"] = org_id
            index_hash["privatekey"] = privatekey
            index_hash["publickey"] = publickey
            index_hash["created_at"] = created_at
            index_hash
        end