From 65c00b2a0dd7eff8bb2688719c307c30afa07cb3 Mon Sep 17 00:00:00 2001 From: Lexus-099 Date: Wed, 28 Oct 2026 20:49:04 +0300 Subject: [PATCH 1/2] Fix Adler-32 checksum for Unicode text --- hashes/adler32.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index 38d76ab12aa0..7f2067703e0b 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -13,18 +13,25 @@ def adler32(plain_text: str) -> int: """ - Function implements adler-32 hash. - Iterates and evaluates a new value for each character + Calculate the Adler-32 checksum of text encoded as UTF-8. + + The checksum is calculated over bytes, so non-ASCII text must be encoded before + processing. UTF-8 provides a consistent byte representation for Python strings. >>> adler32('Algorithms') 363791387 - >>> adler32('go adler em all') 708642122 + >>> adler32('€100') + 196018850 + >>> adler32('日本語テスト') + 2053180537 + >>> adler32('') + 1 """ a = 1 b = 0 - for plain_chr in plain_text: - a = (a + ord(plain_chr)) % MOD_ADLER + for plain_byte in plain_text.encode("utf-8"): + a = (a + plain_byte) % MOD_ADLER b = (b + a) % MOD_ADLER return (b << 16) | a From 561295bd031392d5a4565cee159573225be190a1 Mon Sep 17 00:00:00 2001 From: Lexus-099 Date: Wed, 28 Oct 2026 20:49:41 +0300 Subject: [PATCH 2/2] Align Adler-32 with byte-based checksum definition --- hashes/adler32.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index 7f2067703e0b..66821123051b 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -13,21 +13,14 @@ def adler32(plain_text: str) -> int: """ - Calculate the Adler-32 checksum of text encoded as UTF-8. - - The checksum is calculated over bytes, so non-ASCII text must be encoded before - processing. UTF-8 provides a consistent byte representation for Python strings. + Function implements adler-32 hash. + Iterates over the UTF-8 bytes of the input text. >>> adler32('Algorithms') 363791387 + >>> adler32('go adler em all') 708642122 - >>> adler32('€100') - 196018850 - >>> adler32('日本語テスト') - 2053180537 - >>> adler32('') - 1 """ a = 1 b = 0