cybersecurity · intermediate · ~15 min · safe pentest lab

Digest size from a hex hash

Map a bare hex digest to its bit-length (128/160/256).

Challenge

Before cracking, identify the algorithm family. Implement:

int digest_bits(const char *h);

If h is entirely hex digits and 32/40/64 chars long, return 128/160/256 respectively (MD5-family / SHA-1 / SHA-256). Otherwise return -1.

Input format

A candidate hash string.

Output format

128, 160, 256, or -1.

Constraints

Every character must be a hex digit; length must match exactly.

Starter code

#include <stddef.h>
/* A pure-hex digest of 32/40/64 chars -> 128/160/256 bits (MD5-family/SHA-1/SHA-256). Else -1. */
int digest_bits(const char *h){ (void)h; return -1; }

Common mistakes

Only checking length without validating hex; distinguishing MD5 from NTLM by length alone (you can't — both are 128-bit).

Edge cases to handle

Uppercase hex is valid; 33 hex chars is -1.

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.