cybersecurity · intermediate · ~12 min
Implement a reflected CRC with the bitwise polynomial loop.
Compute the standard IEEE CRC-32 — the integrity check behind zip, PNG, and Ethernet frames.
Implement uint32_t crc32(const uint8_t *data, size_t n) using the IEEE CRC-32 parameters: init 0xFFFFFFFF, reflected polynomial 0xEDB88320, final XOR 0xFFFFFFFF.
data: a byte buffer the grader passes.n: the number of bytes in data.Returns the 32-bit CRC as a uint32_t.
crc32("", 0) -> 0x00000000
crc32("123456789", 9) -> 0xCBF43926 (canonical check value)
crc32("a", 1) -> 0xE8B7BE43
crc32("abc", 3) -> 0x352441C2
0x00000000.CRC-32 (IEEE) is the integrity check behind zip, png, and ethernet frames. Implementing it nails the reflected-polynomial bit loop.
A byte buffer data and its length n.
A uint32_t: the IEEE CRC-32 of the input.
Init 0xFFFFFFFF, reflected poly 0xEDB88320, final XOR 0xFFFFFFFF.
#include <stdint.h>
#include <stddef.h>
uint32_t crc32(const uint8_t *data, size_t n) {
/* TODO */
(void)data; (void)n;
return 0;
}
Wrong (non-reflected) polynomial. Forgetting init 0xFFFFFFFF or the final ~. Signed-shift surprises.
Empty input → 0. The canonical "123456789" check value.
O(n).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.