Calculate password hash from string for use in 'password' fields.
 https://www.openoffice.org/sc/excelfileformat.pdf
557435
def password_hash(pwd)
      hsh = 0
      pwd.reverse.each_char { |c|
        hsh = hsh ^ c.ord
        hsh = hsh << 1
        hsh -= 0x7fff if hsh > 0x7fff
      }

      (hsh ^ pwd.length ^ 0xCE4B).to_s(16)
    end
1254551
def calc_sha(self, checksum):
        
        with LogTask('Calculating {}'.format(checksum)):
            with open(self.dst + '.hash', 'wt') as f:
                sha = utils.get_hash(self.dst, checksum)
                f.write(sha)
            self.exported_metadata[checksum] = sha
845542
def password_hash(password):
    
    try:
        return bcrypt_sha256.encrypt(password)
    except TypeError:
        return bcrypt_sha256.encrypt(password.decode('utf-8'))
446840
def calc_sha(obj):
    """"""
    try:
        pathfile = Path(obj)
    except UnicodeDecodeError:
        pathfile = None
    sha = hashlib.sha256()

    try:
        if pathfile and pathfile.exists():
            return base64.b64encode(pathfile.read_hash('SHA256'))
    except TypeError:
        # likely a bytestring
        if isinstance(obj, string_types):
            pass
        else:
            raise

    if isinstance(obj, string_types):
        sha.update(obj)
    elif hasattr(obj, 'read'):
        while True:
            d = obj.read(8192)
            if not d:
                break
            sha.update(d)
    else:
        return None

    r = sha.digest()
    r = base64.b64encode(r)
    return r
1291924
def _CalculateHashDataStream(self, file_entry, data_stream_name):
    
    hash_context = hashlib.sha256()

    try:
      file_object = file_entry.GetFileObject(data_stream_name=data_stream_name)
    except IOError as exception:
      logging.warning((
          'Unable to open path specification:\n{0:s}'
          'with error: {1!s}').format(
              file_entry.path_spec.comparable, exception))
      return None

    if not file_object:
      return None

    try:
      data = file_object.read(self._READ_BUFFER_SIZE)
      while data:
        hash_context.update(data)
        data = file_object.read(self._READ_BUFFER_SIZE)
    except IOError as exception:
      logging.warning((
          'Unable to read from path specification:\n{0:s}'
          'with error: {1!s}').format(
              file_entry.path_spec.comparable, exception))
      return None

    finally:
      file_object.close()

    return hash_context.hexdigest()
459823
public static String computeGrantFormsHash(Document xml) throws Exception {
		XPathExecutor executor = new XPathExecutor(null);
		executor.setDoc(xml);
		GrantApplicationXpath xpath = new GrantApplicationXpath(null);
		xpath.setExecutor(executor);
		return _hash(xpath);
	}
1042518
public static String calculateSHAHash(String s) throws
    NoSuchAlgorithmException, UnsupportedEncodingException
  {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(s.getBytes("UTF-8"));
    byte[] digest = md.digest();

    StringBuilder hashVal = new StringBuilder();
    for (byte b : digest)
    {
      hashVal.append(String.format("%02x", b));
    }

    return hashVal.toString();
  }
1322384
public function calculateHash()
    {
        // this is the documentation way
        $raw = file_get_contents('php://input');
        $fields = substr($raw, 0, strpos($raw, '&key='));
        $secret = $this->request->getSecret();
        $supposed_hash = md5($fields . $secret);

        // this is how they actually get it
        $kvs = '';
        foreach ($this->data as $k => $v) {
            if ($k !== 'key' && $k !== 'username') {
                $kvs .= ($kvs ? '&' : '') . "$k=$v";
            }
        }
        $hash = md5($kvs);

        /* Testing facility
        dlog([
            'key'    => $this->getHash(),
            'fields' => $fields,
            'kvs'    => $kvs,
            'secret' => $secret,
            'hash'   => $hash,
            'h2'     => md5($fields),
            'h3'     => md5($fields . $secret),
            'kh3'    => md5($kvs),
            'kh4'    => md5($kvs . $secret),
        ]); */

        /// tmp fix
        return $this->getHash();
        //return $hash;
    }
1297299
public static function passwordHash(string $text): ?string
    {
        return password_hash($text, self::PASSWORD_CRYPT_ALGO, [
            'cost' => self::PASSWORD_CRYPT_COST
        ]);
    }
1090473
def hash_file(filepath: str) -> str:
    """"""
    md5 = hashlib.md5()
    acc_hash(filepath, md5)
    return md5.hexdigest()
1139875
def calculate_hash(obj):
    

    hashable_fields = {
        'Chamber': ['name', 'country', 'abbreviation'],
        'Constituency': ['name'],
        'Group': ['name', 'abbreviation', 'kind', 'chamber'],
        'Mandate': ['group', 'constituency', 'role', 'begin_date', 'end_date',
            'representative']
    }

    fingerprint = hashlib.sha1()
    for field_name in hashable_fields[obj.__class__.__name__]:
        field = obj._meta.get_field(field_name)
        if field.is_relation:
            related = getattr(obj, field_name)
            if related is None:
                fingerprint.update(smart_str(related))
            else:
                fingerprint.update(related.fingerprint)
        else:
            fingerprint.update(smart_str(getattr(obj, field_name)))
    obj.fingerprint = fingerprint.hexdigest()
    return obj.fingerprint
766098
def hash(self):
        '''
        
        '''
        hashed = super(Calculated, self).hash()
        return khash(hashed, self._field_name)
1170092
function hash($text)
    {
        $mode = is_array($this->hash) ? self::MODE_INTERNAL : CRYPT_HASH_MODE;

        if (!empty($this->key) || is_string($this->key)) {
            switch ($mode) {
                case self::MODE_MHASH:
                    $output = mhash($this->hash, $text, $this->key);
                    break;
                case self::MODE_HASH:
                    $output = hash_hmac($this->hash, $text, $this->key, true);
                    break;
                case self::MODE_INTERNAL:
                    /* "Applications that use keys longer than B bytes will first hash the key using H and then use the
                        resultant L byte string as the actual key to HMAC."

                        -- http://tools.ietf.org/html/rfc2104#section-2 */
                    $key = strlen($this->key) > $this->b ? call_user_func($this->hash, $this->key) : $this->key;

                    $key    = str_pad($key, $this->b, chr(0));      // step 1
                    $temp   = $this->ipad ^ $key;                   // step 2
                    $temp  .= $text;                                // step 3
                    $temp   = call_user_func($this->hash, $temp);   // step 4
                    $output = $this->opad ^ $key;                   // step 5
                    $output.= $temp;                                // step 6
                    $output = call_user_func($this->hash, $output); // step 7
            }
        } else {
            switch ($mode) {
                case self::MODE_MHASH:
                    $output = mhash($this->hash, $text);
                    break;
                case self::MODE_HASH:
                    $output = hash($this->hash, $text, true);
                    break;
                case self::MODE_INTERNAL:
                    $output = call_user_func($this->hash, $text);
            }
        }

        return substr($output, 0, $this->l);
    }
78817
function hashPw(req, password)
{
	if (password) {
		return req.app.jsl.crypto.createHash('sha1').update(password).digest('hex');
	} else {
		return '';
	}
}
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
883382
private static function __getHash($string)
	{
		return base64_encode(extension_loaded('hash') ?
		hash_hmac('sha1', $string, self::$__secretKey, true) : pack('H*', sha1(
		(str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
		pack('H*', sha1((str_pad(self::$__secretKey, 64, chr(0x00)) ^
		(str_repeat(chr(0x36), 64))) . $string)))));
	}
587247
def hash_password(plaintextpw: str,
                  log_rounds: int = BCRYPT_DEFAULT_LOG_ROUNDS) -> str:
    
    salt = bcrypt.gensalt(log_rounds)  # optional parameter governs complexity
    hashedpw = bcrypt.hashpw(plaintextpw, salt)
    return hashedpw