From 2ca8a29c175b6eab23117ac5664be74b6b385523 Mon Sep 17 00:00:00 2001 From: David Hart Date: Thu, 12 Nov 2026 08:52:21 -0800 Subject: [PATCH] fix(hashes): compute Adler-32 over UTF-8 bytes Preserve the text API while checksumming encoded bytes rather than Unicode code points. Document UTF-8 encoding and strict encoding errors without changing doctests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- hashes/adler32.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index 38d76ab12aa0..9322970f2970 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -13,8 +13,8 @@ def adler32(plain_text: str) -> int: """ - Function implements adler-32 hash. - Iterates and evaluates a new value for each character + Compute the Adler-32 checksum of the text's UTF-8 bytes. + Text that cannot be encoded as UTF-8 raises UnicodeEncodeError. >>> adler32('Algorithms') 363791387 @@ -24,7 +24,7 @@ def adler32(plain_text: str) -> int: """ a = 1 b = 0 - for plain_chr in plain_text: - a = (a + ord(plain_chr)) % MOD_ADLER + for byte in plain_text.encode("utf-8"): + a = (a + byte) % MOD_ADLER b = (b + a) % MOD_ADLER return (b << 16) | a