cybersecurity · beginner · ~15 min
Compute the padded base64 output size.
Compute how many characters the padded base64 encoding of some bytes will take — the size you must allocate before encoding.
Implement int base64_len(int n) that returns the length of the base64 encoding of n input bytes.
n: the number of raw input bytes.Returns int: the padded base64 length, 4 * ceil(n / 3), i.e. 4 * ((n + 2) / 3).
base64_len(3) -> 4
base64_len(1) -> 4
base64_len(6) -> 8
base64_len(0) -> 0
=).An int n: the number of raw input bytes.
An int: the padded base64 length 4 * ((n + 2) / 3).
Round each 3-byte group up to 4 characters.
int base64_len(int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.