cybersecurity · beginner · ~15 min
Case-insensitive substring scan; per-line iteration.
Audit a config blob for deprecated crypto by counting how many lines name a known-weak algorithm.
Implement int weak_crypto_count(const char *config) that returns the number of lines mentioning any of these weak algorithms, matched case-insensitively as a substring: MD5, SHA1, DES, RC4, 3DES.
A line counts once even if it names several weak algorithms.
config: a NUL-terminated, multi-line config string the grader provides. Lines are separated by \n.Returns the count of lines that contain at least one weak-algorithm name, as an int.
"cipher = AES-256\nhash = MD5\nfallback = sha1\n" -> 2
"old = des-ede3 (3des)\ntransport = rc4-md5\n" -> 2 (each line counted once)
"safe = sha256\n" -> 0
"" -> 0
sha1 inside sha10.Auditing config files for deprecated crypto is the kind of grep-able problem real security tools (semgrep, bandit, OpenSSL hardener) solve every day. Implementing one teaches the alert-vs-allow distinction.
A NUL-terminated multi-line config string (lines separated by \n).
Count of lines naming any of MD5/SHA1/DES/RC4/3DES, as an int.
Case-insensitive substring match; each line counts at most once.
int weak_crypto_count(const char *config) { /* TODO */ return 0; }
Counting SHA256 as SHA1 (need word boundary or proper token check — for this exercise substring is fine, but watch the test cases); counting the same line twice when two algorithms appear.
Empty input. Line with two weak ciphers — counts once.
O(n * weak_count).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.