Repository navigation
Conversation
Adler-32 is defined over a byte stream, but the implementation summed Unicode code points, so any non-ASCII input produced a checksum that no standard implementation would produce (round-trip/verification broken). Iterate the UTF-8 encoded bytes instead, matching zlib.adler32(text.encode()) for every input. Verified with doctests and 500 randomized cross-checks against zlib. Fixes TheAlgorithms#15635
mindaugl
approved these changes
Nov 12, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
Fixes #15635
Adler-32 is defined over a byte stream, but
hashes/adler32.pysummedUnicode code points, so any non-ASCII input produced a checksum that no
standard implementation would produce (e.g.
adler32('€100')returned2211914046instead of196018850).This PR iterates the UTF-8 encoded bytes instead of the characters, so the
result now matches the reference implementation
zlib.adler32(text.encode())for every input, and aligns with the sibling module
hashes/crc32.py(which already takes bytes and matches
zlib.crc32).Doctests added: the non-ASCII examples from the issue, plus a cross-check
against
zlib.adler32. Also verified locally with 500 randomized inputs(ASCII, Latin-1, CJK, emoji) against zlib — all match.
ruff checkandruff format --checkpass.Checklist