Skip to content

Commit

Permalink
Hash adler32 (#2111)
Browse files Browse the repository at this point in the history
* implement hash

* fix indentation
  • Loading branch information
bnMikheili committed Jun 14, 2020
1 parent ae9d0f9 commit 55b3088
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions hashes/adler32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Adler-32 is a checksum algorithm which was invented by Mark Adler in 1995.
Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter).
Adler-32 is more reliable than Fletcher-16, and slightly less reliable than Fletcher-32.[2]
source: https://en.wikipedia.org/wiki/Adler-32
"""


def adler32(plain_text: str) -> str:
"""
Function implements adler-32 hash.
Itterates and evaluates new value for each character
>>> adler32('Algorithms')
363791387
>>> adler32('go adler em all')
708642122
"""
MOD_ADLER = 65521
a = 1
b = 0
for plain_chr in plain_text:
a = (a + ord(plain_chr)) % MOD_ADLER
b = (b + a) % MOD_ADLER
return (b << 16) | a

0 comments on commit 55b3088

Please sign in to comment.