Safe Penetration Testing Labs · beginner · ~10 min
Format a contactless-card UID byte array as a colon-separated hex string.
Validate n, walk the byte array, emit %02X then : (except after the last byte), NUL.
The UID format is the lingua franca of every NFC log. Getting the render right means your logs are diffable against any other tool.
ISO/IEC 14443 is the standard behind every contactless card —
transit passes, hotel keys, NFC tags. The UID is 4, 7, or 10 bytes.
Every NFC tool prints it the same way: AA:BB:CC:DD.
This exercise is the formatter side. Reading a UID from a real PN532 or PN5180 reader is a separate firmware project.
Implement int format_uid(const uint8_t *uid, size_t n, char *out, size_t cap).
Render uid into out as uppercase hex, colon-separated, NUL-
terminated. Return the number of bytes written (excluding NUL).
Rules:
n must be 4, 7, or 10. Anything else → -1.n * 3 - 1 bytes (each byte is 2 hex chars + a
separator, minus the trailing one). Plus 1 for NUL.cap is too small.sprintf with %02x and getting lowercase. Use %02X or
format by hand.Three valid lengths, bounded output, uppercase hex with colon separators.