cybersecurity · intermediate · ~15 min · safe pentest lab
Build a streaming checksum.
Compute Fletcher's 32-bit checksum over a block of bytes — a fast, non-cryptographic integrity check made of two running sums.
Implement uint32_t fletcher32(const unsigned char *data, size_t n) using the exact variant pinned below.
data[i] | (data[i+1] << 8).sum1 = (sum1 + word) % 65535 then sum2 = (sum2 + sum1) % 65535.(sum2 << 16) | sum1.data: a byte buffer the grader provides (the fixtures are short fixed strings).n: the number of bytes in data.Returns the 32-bit checksum as a uint32_t.
fletcher32("", 0) -> 0x00000000
fletcher32("abc", 3) -> 0xC52562C4
fletcher32("aaaa",4) -> 0x2424C2C2
n == 0: returns 0.n: the trailing byte is processed as one half-word.A byte buffer data and its length n (fixtures are short fixed strings).
The 32-bit Fletcher checksum (sum2 << 16) | sum1, as a uint32_t.
Use the pinned little-endian-word variant; both sums modulo 65535.
#include <stdint.h>
#include <stddef.h>
uint32_t fletcher32(const unsigned char *data, size_t n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.