Python
Python copied to clipboard
feat: add CRC32 hash algorithm implementation
Description
Implements the CRC32 (Cyclic Redundancy Check 32-bit) hash algorithm, which is widely used for error detection and data integrity verification.
Changes
- Added hashes/crc32.py with complete implementation
- Uses IEEE 802.3 polynomial (0xEDB88320)
- Optimized with pre-calculated lookup table
- 17 comprehensive doctests including edge cases
- Cross-validated against Python's zlib.crc32()
Real-world Applications
- ZIP file format
- Ethernet frames
- PNG images
- GZIP compression
- Data integrity verification
- Error detection in network protocols
References
- https://en.wikipedia.org/wiki/Cyclic_redundancy_check
- https://www.rfc-editor.org/rfc/rfc1952
Testing
- All 17 doctests pass
- Passes ruff linting
- Passes mypy type checking
- Validated correctness against standard library zlib.crc32()
Checklist
- [x] I have read and followed the contributing guidelines
- [x] This pull request is not a duplicate
- [x] The algorithm is implemented from scratch
- [x] The code follows the repository style
- [x] I have read CONTRIBUTING.md
- [x] This pull request is all my own work -- I have not plagiarized
- [x] I know that pull requests will not be merged if they fail the automated tests
- [x] This PR only changes one algorithm file
- [x] All new Python files are placed inside an existing directory (hashes/)
- [x] All filenames are in all lowercase characters with no spaces or dashes
- [x] All functions and variable names follow Python naming conventions
- [x] All function parameters and return values are annotated with Python type hints
- [x] All functions have doctests that pass the automated testing
- [x] All new algorithms include at least one URL that points to Wikipedia or another similar explanation