2023 Cyber Apocalypse: Ancient Encodings
Challenge Information
| Attribute | Details |
|---|---|
| Event | 2023 Cyber Apocalypse |
| Category | Crypto |
| Challenge | Ancient Encodings |
Summary
This challenge presents an encoding scheme that combines base64 encoding with hexadecimal conversion. The goal is to reverse the encoding process to recover the original flag. The encoding function takes a message, applies base64 encoding, then converts the result to hexadecimal representation.
Analysis
The challenge provides:
- Source code showing the encoding process
- An encoded output in hexadecimal format
The encoding process is straightforward:
- Input message is base64 encoded using
b64encode() - The base64 bytes are converted to a long integer using
bytes_to_long() - The result is converted to hexadecimal using
hex()
The output provided is:
0x53465243657a467558336b7764584a66616a4231636d347a655639354d48566664326b786246397a5a544e66644767784e56396c626d4d775a4446755a334e665a58597a636e6c33614756794d33303dSolution
To solve this challenge, we need to reverse the encoding:
- Remove the ‘0x’ prefix from the hexadecimal string
- Convert the hexadecimal string to bytes
- Apply base64 decoding
Here’s the solution approach:
from base64 import b64decodeimport binascii
# The encoded outputencoded_hex = "53465243657a467558336b7764584a66616a4231636d347a655639354d48566664326b786246397a5a544e66644767784e56396c626d4d775a4446755a334e665a58597a636e6c33614756794d33303d"
# Convert hex to bytesencoded_bytes = binascii.unhexlify(encoded_hex)
# Base64 decodeflag = b64decode(encoded_bytes).decode()print(flag)This process reverses the steps:
- Hexadecimal string → bytes
- Base64 decoding → original message
Key Takeaways
- Understanding encoding layers is crucial for cryptography challenges
- Many “crypto” challenges are actually about reverse-engineering encoding schemes
- Base64 and hexadecimal are common encoding methods used in CTFs
- Working backwards through the encoding process is the standard approach