Skip to content
Zone for Exploration and
Understanding of Security
← All writeups
Reverse Engineering Medium

Hidden Cipher 2

CyLab 2026 · Reverse Engineering · Medium

Technique
Static RE of a reversible transform
The transform
encoded = flag_byte × answer
Tools
file, strings, objdump, Python
Binary
ELF64 PIE, not stripped
Attack Chain
Triagefile, strings
→
Static Analysisobjdump, encode_flag
→
Reverse the Transformdivision inverts multiplication
→
Impactflag decoded

Vulnerability Analysis

Root Cause: The "encoding" is a single known multiplication, not an actual cryptographic transform — anyone who knows the multiplier (the math prompt's own answer) can invert it with one division per byte.

  • CWE-327: Use of a Broken or Risky Cryptographic Algorithm — A trivially-invertible multiply stands in for encryption and offers no real confidentiality

Severity: No CVSS score applies — this is a lab-built obfuscation, not a scored vulnerability in a shipped product.

References:
CWE-327

Summary

The binary asks a simple math question (What is A op B?). Answer correctly and it prints the flag — but encoded: each flag byte is multiplied by your answer. Because multiplication is reversible, dividing each encoded value by the answer recovers the original byte.

The “cipher” is just encoded = flag_byte × answer. Knowing the answer, flag_byte = encoded ÷ answer — a clean, exact inverse.

Recon & static analysis

Standard triage, then read the disassembly — the binary isn't stripped, so function names survive:

shell
file hiddencipher2           # ELF 64-bit PIE, not stripped
strings hiddencipher2 | head  # "Encoded flag values:", "%d %c %d?", ...
objdump -d hiddencipher2 | grep -A200 '<main>'
objdump -d hiddencipher2 | grep -A100 '<encode_flag>'

In encode_flag the transform is plain: for each character it prints flag_byte * answer, comma-separated. So the decode is one division per value.

Automated solve

The solver parses the question, computes the answer, sends it, reads the encoded list, and divides it back:

python
m = re.search(r'What is (\d+) ([+\-*]) (\d+)\?', prompt)
a, op, b = int(m[1]), m[2], int(m[3])
answer = a+b if op=='+' else abs(a-b) if op=='-' else a*b
sock.sendall(f"{answer}\n".encode())

encoded = [int(x) for x in re.search(r'Encoded flag values:\s*\n([\d,\s]+)', out)[1].split(',') if x.strip().isdigit()]
flag = bytes(v // answer for v in encoded).decode()
print(flag)
Remote runner
shell
python3 solve_remote.py shape-of-you.picoctf.net 49821

Takeaways

  • Start with file + strings. The strings named the exact behaviour before any disassembly.
  • Unstripped symbols made locating encode_flag trivial.
  • A reversible transform is not encryption. Multiply-by-known inverts cleanly with division.

References & Standards

Practice next

Explore more reverse engineering challenges on CyLab Security Academy.

Explore CyLab Security Academy ↗