← Back to Writeups
CUSTOMEasyCrypto

Забытый (Forgotten)

XESXOR9/2/20262 min read
#crypto#custom#easy#key-pattern-recognition#python-escape-sequence-decodin#xor-known-plaintext-attack

Забытый (Forgotten)

Platform: CUSTOM | Category: Crypto | Type: Challenge | Difficulty: Easy | OS: N/A | **Author: XESXOR Techniques: Key pattern recognition, Python escape sequence decoding, XOR known-plaintext attack

Summary

Walkthrough of the CUSTOM Crypto Забытый (Forgotten). Task: XOR-encrypted ciphertext with Python escape sequences. Solution: Known-plaintext attack using flag format prefix to recover repeating 4-byte key.

Description

Я решил попробовать шифрование XOR-ом, но забыл секретный ключ...

Files: forgotten.zip → cyphertext.txt

Analysis

1. Examining the ciphertext

The file cyphertext.txt contains Python-style escape sequences:

+\x7ft1*iK\x1c[Io\x16\x1a\x00o\x1aYS\x03+\x10\x00B\t

2. Decoding escape sequences

Convert escape sequences to bytes:

python
raw = b'+\x7ft1*iK\x1c[Io\x16\x1a\x00o\x1aYS\x03+\x10\x00B\t'
print(raw.hex())
# 2b7f74312a694b1c5b496f161a006f1a5953032b10004209

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

We get 24 bytes of ciphertext.

3. Known-Plaintext Attack

Knowing the flag format CODEBY{, XOR the first 7 bytes of ciphertext with the known plaintext:

python
ciphertext = bytes.fromhex('2b7f74312a694b1c5b496f161a006f1a5953032b10004209')
known_prefix = b'CODEBY{'

# Recover part of the key
key_fragment = bytes([c ^ p for c, p in zip(ciphertext[:7], known_prefix)])
print(key_fragment)  # b'h00th00'

4. Determining the key

We see a repeating pattern: h00th00 → key is h00t (4 bytes).

Solution

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

python
#!/usr/bin/env python3
"""
XOR Known-Plaintext Attack
Task: Забытый (Forgotten) - hackerlab
"""

# Ciphertext (decoded escape sequences)
ciphertext = bytes.fromhex('2b7f74312a694b1c5b496f161a006f1a5953032b10004209')

# Known flag prefix
known_prefix = b'CODEBY{'

# Recover the key via XOR with known plaintext
key_fragment = bytes([c ^ p for c, p in zip(ciphertext[:7], known_prefix)])
print(f"Key fragment: {key_fragment}")  # b'h00th00'

# Determine the full key (repeating pattern)
key = b'h00t'
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Decrypt
def xor_decrypt(data, key):
    return bytes([data[i] ^ key[i % len(key)] for i in range(len(data))])

plaintext = xor_decrypt(ciphertext, key)
print(f"Flag: {plaintext.decode()}")

Theory

XOR Known-Plaintext Attack

XOR has the property: C = P ⊕ K → K = C ⊕ P

If plaintext P and ciphertext C are known, key K is recovered trivially.

Repeating-Key XOR

When using a short key, it repeats cyclically:

  • plaintext[0] ⊕ key[0]
  • plaintext[1] ⊕ key[1]
  • ...
  • plaintext[n] ⊕ key[n % len(key)] ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Knowing len(key) bytes of plaintext, the entire key can be recovered.

References

  • XOR Cipher
  • Known-plaintext attack ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Key Takeaways / Lessons

  • Mastering Key pattern recognition, Python escape sequence decoding, XOR known-plaintext attack was key to this challenge.
  • Always check for common misconfigurations and verify assumptions.

Crafted by XESXOR Research • 2025-12-24 • CUSTOM • Забытый (Forgotten) • Difficulty: Easy