def simple_hash(text, key='', salt='', digest_alg='md5'):
 text = to_bytes(text)
 key = to_bytes(key)
 salt = to_bytes(salt)
 if (not digest_alg):
  raise RuntimeError('simple_hash with digest_alg=None')
 elif (not isinstance(digest_alg, str)):
  h = digest_alg(((text + key) + salt))
 elif digest_alg.startswith('pbkdf2'):
  (iterations, keylen, alg) = digest_alg[7:(-1)].split(',')
  return to_native(pbkdf2_hex(text, salt, int(iterations), int(keylen), get_digest(alg)))
 elif key:
  digest_alg = get_digest(digest_alg)
  h = hmac.new((key + salt), text, digest_alg)
 else:
  h = get_digest(digest_alg)()
  h.update((text + salt))
 return h.hexdigest()

def simple_hash ( text , key = '' , salt = '' , digest_alg = 'md5' ) : text = to_bytes ( text ) key = to_bytes ( key ) salt = to_bytes ( salt ) if ( not digest_alg ) : raise RuntimeError ( 'simple_hash with digest_alg=None' ) elif ( not isinstance ( digest_alg , str ) ) : h = digest_alg ( ( ( text + key ) + salt ) ) elif digest_alg . startswith ( 'pbkdf2' ) : ( iterations , keylen , alg ) = digest_alg [ 7 : ( - 1 ) ] . split ( ',' ) return to_native ( pbkdf2_hex ( text , salt , int ( iterations ) , int ( keylen ) , get_digest ( alg ) ) ) elif key : digest_alg = get_digest ( digest_alg ) h = hmac . new ( ( key + salt ) , text , digest_alg ) else : h = get_digest ( digest_alg ) ( ) h . update ( ( text + salt ) ) return h . hexdigest ( )
generate hash with the given text using the specified digest algorithm .