MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / sdbm

Function sdbm

hashes/sdbm.py:22–39  ·  view source on GitHub ↗

Function implements sdbm hash, easy to use, great for bits scrambling. iterates over each character in the given string and applies function to each of them. >>> sdbm('Algorithms') 1462174910723540325254304520539387479031000036 >>> sdbm('scramble bits') 730247649148944

(plain_text: str)

Source from the content-addressed store, hash-verified

20
21
22def sdbm(plain_text: str) -> int:
23 """
24 Function implements sdbm hash, easy to use, great for bits scrambling.
25 iterates over each character in the given string and applies function to each of
26 them.
27
28 >>> sdbm('Algorithms')
29 1462174910723540325254304520539387479031000036
30
31 >>> sdbm('scramble bits')
32 730247649148944819640658295400555317318720608290373040936089
33 """
34 hash_value = 0
35 for plain_chr in plain_text:
36 hash_value = (
37 ord(plain_chr) + (hash_value << 6) + (hash_value << 16) - hash_value
38 )
39 return hash_value

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected