2023 Cyber Apocalypse: Ancient Encodings

Challenge Information

AttributeDetails
Event2023 Cyber Apocalypse
CategoryCrypto
ChallengeAncient 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:

  1. Input message is base64 encoded using b64encode()
  2. The base64 bytes are converted to a long integer using bytes_to_long()
  3. The result is converted to hexadecimal using hex()

The output provided is:

0x53465243657a467558336b7764584a66616a4231636d347a655639354d48566664326b786246397a5a544e66644767784e56396c626d4d775a4446755a334e665a58597a636e6c33614756794d33303d

Solution

To solve this challenge, we need to reverse the encoding:

  1. Remove the ‘0x’ prefix from the hexadecimal string
  2. Convert the hexadecimal string to bytes
  3. Apply base64 decoding

Here’s the solution approach:

from base64 import b64decode
import binascii
# The encoded output
encoded_hex = "53465243657a467558336b7764584a66616a4231636d347a655639354d48566664326b786246397a5a544e66644767784e56396c626d4d775a4446755a334e665a58597a636e6c33614756794d33303d"
# Convert hex to bytes
encoded_bytes = binascii.unhexlify(encoded_hex)
# Base64 decode
flag = 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