From d2a5847b897960efc0f4ac401e31aa05cc26b818 Mon Sep 17 00:00:00 2001 From: bnMikheili Date: Sat, 13 Jun 2020 20:52:48 +0400 Subject: [PATCH 1/2] implement hash --- 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 000000000000..8b82fff477fd --- /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 From 38f3b5c59c0cdf3de70ae5253fa1db4b8bf40a86 Mon Sep 17 00:00:00 2001 From: bnMikheili Date: Sat, 13 Jun 2020 20:53:56 +0400 Subject: [PATCH 2/2] fix indentation --- conversions/decimal_to_any.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conversions/decimal_to_any.py b/conversions/decimal_to_any.py index d3acac3bd41e..5abcb8e6549f 100644 --- a/conversions/decimal_to_any.py +++ b/conversions/decimal_to_any.py @@ -67,9 +67,9 @@ def decimal_to_any(num: int, base: int) -> str: raise ValueError("base must be <= 36") # fmt: off ALPHABET_VALUES = {'10': 'A', '11': 'B', '12': 'C', '13': 'D', '14': 'E', '15': 'F', '16': 'G', '17': 'H', - '18': 'I', '19': 'J', '20': 'K', '21': 'L', '22': 'M', '23': 'N', '24': 'O', '25': 'P', - '26': 'Q', '27': 'R', '28': 'S', '29': 'T', '30': 'U', '31': 'V', '32': 'W', '33': 'X', - '34': 'Y', '35': 'Z'} + '18': 'I', '19': 'J', '20': 'K', '21': 'L', '22': 'M', '23': 'N', '24': 'O', '25': 'P', + '26': 'Q', '27': 'R', '28': 'S', '29': 'T', '30': 'U', '31': 'V', '32': 'W', '33': 'X', + '34': 'Y', '35': 'Z'} # fmt: on new_value = "" mod = 0