cybersecurity · beginner · ~15 min

Valid base64 character?

Validate the base64 alphabet.

Challenge

Check whether a character belongs to the base64 alphabet — the per-character guard that rejects malformed or injected tokens before decoding.

Task

Implement int is_base64_char(char c) that returns 1 if c is part of standard base64, else 0.

Input

  • c: a single character the grader passes.

Output

Returns int: 1 for A-Z, a-z, 0-9, +, /, and the padding =; else 0.

Example

is_base64_char('A')   ->   1
is_base64_char('+')   ->   1
is_base64_char('=')   ->   1   (padding)
is_base64_char('!')   ->   0

Edge cases

  • The padding character = counts as valid.

Input format

A single character c.

Output format

An int: 1 if c is a base64 char (incl. =), else 0.

Constraints

Standard alphabet A-Za-z0-9+/ plus padding =.

Starter code

int is_base64_char(char c) {
    /* TODO */
    return 0;
}

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