The Challenge
The server sends a JSON object with a message field and an Italian instruction describing the conversion: da base64, da esadecimale, da binario, a base64, a esadecimale, a binario. Respond with {"answer": "..."} and repeat until the flag appears.
Approach
Six transformations, each handled by one branch:
da base64→b64decode(message)da esadecimale→bytes.fromhex(message)da binario→ convert binary string to int, then to bytesa base64→b64encode(message.encode())a esadecimale→message.encode().hex()a binario→ format each character as 8-bit binary, strip leading zero if the string doesn’t start with1
The only tricky case is a binario: standard binary representation of an ASCII string can have a leading zero byte, and the server apparently strips/ignores the leading 0 bit, so we check whether binstr[0] is '1' and if not walk forward to the first '1'.
The response body is always b'{"answer": "' + value + b'"}.
Solution
|
|
eval(t[1]) parses the raw JSON line as a Python dict — quick and dirty but fine for CTF. The response is assembled as raw bytes to avoid encoding issues where the decoded/encoded value might not be valid UTF-8.
What I Learned
Encoding challenges are solved faster by just implementing all six directions up front rather than trying to predict which direction the server picks. The bin_to_str helper — int(x, 2).to_bytes(...) — is a pattern worth memorising: it converts an arbitrary-length binary string to bytes without looping character by character.