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

Function adler32

hashes/adler32.py:14–30  ·  view source on GitHub ↗

Function implements adler-32 hash. Iterates and evaluates a new value for each character >>> adler32('Algorithms') 363791387 >>> adler32('go adler em all') 708642122

(plain_text: str)

Source from the content-addressed store, hash-verified

12
13
14def adler32(plain_text: str) -> int:
15 """
16 Function implements adler-32 hash.
17 Iterates and evaluates a new value for each character
18
19 >>> adler32('Algorithms')
20 363791387
21
22 >>> adler32('go adler em all')
23 708642122
24 """
25 a = 1
26 b = 0
27 for plain_chr in plain_text:
28 a = (a + ord(plain_chr)) % MOD_ADLER
29 b = (b + a) % MOD_ADLER
30 return (b << 16) | a

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected