Created
March 3, 2026 22:29
-
-
Save casebeer/d6ac799e0acb6c771ebdf8ed8f3c0492 to your computer and use it in GitHub Desktop.
Ethernet CRC computation with Python zlib.crc32
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
| import struct | |
| import zlib | |
| testVector = ( | |
| # input is ascii string | |
| bytearray(ord(c) for c in "123456789"), | |
| bytearray([ 0xCB, 0xF4, 0x39, 0x26]), | |
| ) | |
| crc = zlib.crc32(testVector[0]) | |
| crcBytes = struct.pack('>I', crc) # big endian!? | |
| print(f"Computed: {crcBytes.hex()}") | |
| print(f"Expected: {testVector[1].hex()}") | |
| assert crcBytes == testVector[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment