cybersecurity · beginner · ~12 min · safe pentest lab
Linear-time deduplication against a fixed-capacity seen-set in pure C.
Count the unique non-empty subdomains in a wordlist — deduplicating recon wordlists is the linear-scan-plus-small-table pattern in pure C.
Implement int count_unique_domains(const char *list) that returns the number of distinct non-empty entries, compared case-insensitively.
list: a NUL-terminated, \n-separated string of subdomain labels baked into the harness.Returns int: the number of unique non-empty entries, 0 if list == NULL, or -1 if there are more than 256 distinct entries.
"www\napi\nwww\nmail\n" -> 3
"www\nWWW\n" -> 1 (case-insensitive)
"\n\n\n" -> 0
NULL -> 0
\n; stop at the NUL.\n, lowercase each token, and linear-scan a fixed seen-table.Recon pipelines start by deduplicating wordlists. Writing the deduper in C teaches the linear-scan + small-table pattern.
A NUL-terminated string of \n-separated subdomain labels.
Unique count (0..256), or -1 if the cap is exceeded.
Cap distinct entries at 256. Per-entry label <= 63 chars.
int count_unique_domains(const char *list) {
/* TODO */
(void)list;
return 0;
}
Forgetting trailing-NL-less input. Allowing empty lines through. Reading past NUL.
Cap at exactly 256. Case variation. Single line without newline.
O(input_len * unique_count). Bounded by 256 unique × 64 bytes.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.