cybersecurity · intermediate · ~15 min · safe pentest lab
Hex-encode a byte buffer.
Hex-encode a card UID — RFID/NFC UIDs are logged and compared as hex strings.
Implement int uid_to_hex(const unsigned char *uid, int n, char *out, int outsz) that writes the lowercase hex of the n bytes of uid into out, NUL-terminating, and returns the number of hex characters written (n*2).
uid: a byte buffer of length n. The grader passes a fixed buffer.n: the number of bytes to encode.out, outsz: the output buffer and its capacity.Returns int: n*2 on success (with out holding n*2 lowercase hex chars plus a NUL), or -1 if out cannot hold n*2 + 1 bytes.
uid = {0x04, 0xA2, 0xBF}, n = 3, outsz = 8 -> out = "04a2bf", returns 6
outsz = 4 -> -1 (won't fit)
outsz >= n*2 + 1.A byte buffer uid of length n, an output buffer out, and its size outsz.
An int: n*2 on success (out is lowercase hex + NUL), or -1 if too small.
Lowercase hex. Need outsz >= n*2+1 or return -1.
int uid_to_hex(const unsigned char *uid, int n, char *out, int outsz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.