cybersecurity · intermediate · ~15 min · safe pentest lab

Build a 32-bit checksum tool

Build a streaming checksum.

Challenge

Implement uint32_t fletcher32(const unsigned char *data, size_t n) — Fletcher's 32-bit checksum, defined as two running sums modulo 65535 combined. It's a fast non-cryptographic checksum useful for integrity verification of local files.

Variant pinned for this exercise

Bytes are packed into 16-bit words little-endian (data[i] | (data[i+1] << 8)). For odd-length inputs the trailing byte is read as a half-word in the low byte. Both sums start at 0 and are reduced modulo 65535. Final value is (sum2 << 16) | sum1.

(For cryptographic integrity, use SHA-256 — not implementing here; the goal is to practise the streaming sum pattern.)

Starter code

#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.