Skip to content

Instantly share code, notes, and snippets.

@casebeer
Created March 3, 2026 22:29
Show Gist options
  • Select an option

  • Save casebeer/d6ac799e0acb6c771ebdf8ed8f3c0492 to your computer and use it in GitHub Desktop.

Select an option

Save casebeer/d6ac799e0acb6c771ebdf8ed8f3c0492 to your computer and use it in GitHub Desktop.
Ethernet CRC computation with Python zlib.crc32
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