From 55b3088e47690f2a8a152ceb44bba786810abb28 Mon Sep 17 00:00:00 2001 From: bnMikheili <39998190+bnMikheili@users.noreply.github.com> Date: Sun, 14 Jun 2020 11:49:39 +0400 Subject: [PATCH] Hash adler32 (#2111) * implement hash * fix indentation --- hashes/adler32.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 hashes/adler32.py diff --git a/hashes/adler32.py b/hashes/adler32.py new file mode 100644 index 000000000..8b82fff47 --- /dev/null +++ b/hashes/adler32.py @@ -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