Every line of 'python hash a string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
27 def hash(type, str): 28 return digest[type](str).hexdigest()
25 def Hash(x): 26 if type(x) is unicode: 27 x = x.encode('utf-8') 28 return sha256(sha256(x))
100 def Hash(x): 101 if type(x) is unicode: x = x.encode('utf-8') 102 return sha256(sha256(x)) 103 return r
4 def hash256(string): 5 return hashlib.sha256(hashlib.sha256(string).digest()).digest()
56 @staticmethod 57 def hash(s): 58 return sha256(s.encode()).hexdigest()
20 def test_string_hashing(self): 21 h1 = Hasher() 22 h1.update("Hello, world!") 23 h2 = Hasher() 24 h2.update("Goodbye!") 25 h3 = Hasher() 26 h3.update("Hello, world!") 27 self.assertNotEqual(h1.hexdigest(), h2.hexdigest()) 28 self.assertEqual(h1.hexdigest(), h3.hexdigest())
86 def hash(self, w_obj): 87 return w_obj.hash(self)
79 def hash_value(self, value, salt=''): 80 '''Hashes the specified value combined with the specified salt. 81 The hash is done HASHING_ROUNDS times as specified by the application 82 configuration. 83 84 An example usage of :class:``hash_value`` would be:: 85 86 val_hash = hashing.hash_value('mysecretdata', salt='abcd') 87 # save to a db or check against known hash 88 89 :param value: The value we want hashed 90 :param salt: The salt to use when generating the hash of ``value``. Default is ''. 91 :return: The resulting hash as a string 92 :rtype: str 93 ''' 94 def hashit(value, salt): 95 h = hashlib.new(self.algorithm) 96 tgt = salt+value 97 h.update(tgt) 98 return h.hexdigest() 99 100 def fix_unicode(value): 101 if VER < 3 and isinstance(value, unicode): 102 value = str(value) 103 elif VER >= 3 and isinstance(value, str): 104 value = str.encode(value) 105 return value 106 107 salt = fix_unicode(salt) 108 for i in range(self.rounds): 109 value = fix_unicode(value) 110 value = hashit(value, salt) 111 return value
1727 def repr(self): 1728 arg_repr = ["(%s => %s)" % (k, v.repr()) for k, v in self.initializers] 1729 return 'Hash([%s])' % ', '.join(arg_repr)
44 def py_djb_hash(s): 45 u""" 46 Return the value of DJB's hash function for the given 8-bit string. 47 48 >>> py_djb_hash('') 49 5381 50 >>> py_djb_hash('\x01') 51 177572 52 >>> py_djb_hash('€') 53 193278953 54 """ 55 h = 5381 56 for c in s.encode('UTF-8'): 57 h = (((h << 5) + h) ^ c) & 0xffffffff 58 return h