cybersecurity · intermediate · ~15 min · safe pentest lab
Find the peak byte frequency — a flat histogram (low peak) signals high entropy.
Complement the distinct-count signal with flatness:
int max_byte_frequency(const unsigned char *buf, size_t n);
Return the count of the single most frequent byte value. Encrypted data is flat (a low peak); plaintext spikes (spaces, e, ...).
buf of n bytes.
The count of the most frequent byte (0 if n==0).
n==0 returns 0.
#include <stddef.h>
/* Count of the MOST frequent byte value in buf (0 if n==0). Flat (low) => high entropy. */
int max_byte_frequency(const unsigned char *buf, size_t n){ (void)buf;(void)n; return 0; }
Returning the byte value instead of its count; not handling the empty buffer.
All-same returns n; a flat 256-value buffer returns n/256 rounded down per value.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.