← Back to Writeups
CUSTOMEasyCrypto

Поврежденная расшифровка (Corrupted Decryption)

XESXOR9/2/20263 min read
#crypto#custom#easy#key-recovery-from-partial-plai#known-plaintext-attack-on-xor-#repeating-key-pattern-detectio

Поврежденная расшифровка (Corrupted Decryption)

Platform: CUSTOM | Category: Crypto | Type: Challenge | Difficulty: Easy | OS: N/A | **Author: XESXOR Techniques: Key recovery from partial plaintext, Known-plaintext attack on XOR cipher, Repeating key pattern detection

Summary

Walkthrough of the CUSTOM Crypto Поврежденная расшифровка (Corrupted Decryption). Task: XOR-encrypted ciphertext with partial plaintext containing null bytes as unknown position markers. Solution: Known-plaintext attack to recover key bytes, then detect repeating key pattern (23 by

Description

При расшифровке что-то пошло не так, поможешь? (Something went wrong during decryption, can you help?)

A file corrupted_decryption.txt with two hex strings was provided.

Analysis

Initial Data

The file contains:

  • ct — ciphertext (512 bytes in hex)
  • partial text — partially recovered plaintext with many null bytes
ct = 048ab14c84a3d440d97e1823e25d1c0ebde77230c31a51388bf24ec1b4c213c4...
partial text = 000000000073730000000000000000000000000000200000000061000000730000...

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

Cipher Type Identification

  1. Equal length — ct and partial text have the same length (512 bytes)
  2. Null bytes — partial text contains many 00, meaning "unknown" positions
  3. XOR property — if C ⊕ K = P, then C ⊕ P = K

This is a classic XOR cipher with a repeating key.

Key Recovery

For each position where plaintext is known (not 0x00):

key[i] = ciphertext[i] ⊕ plaintext[i]

Analysis showed that the key repeats with a period of 23 bytes.

Solution

python
import binascii
import os
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

file_path = os.path.join(os.path.dirname(__file__), 'corrupted_decryption.txt')

with open(file_path, 'r') as f:
    lines = f.readlines()
    ct_hex = lines[0].split('=')[1].strip()
    pt_hex = lines[1].split('=')[1].strip()

ct = binascii.unhexlify(ct_hex)
pt_partial = binascii.unhexlify(pt_hex)

# Recover key bytes where plaintext is known
key_partial = []
for c, p in zip(ct, pt_partial):
    if p != 0:
        key_partial.append(c ^ p)
    else:
        key_partial.append(None)

# Find repeating pattern in key
def find_pattern(arr):
    for length in range(1, 100):
        full_pattern = [None] * length
        possible = True
        for i in range(len(arr)):
            if arr[i] is not None:
                if full_pattern[i % length] is not None and full_pattern[i % length] != arr[i]:
                    possible = False
                    break
                full_pattern[i % length] = arr[i]
        if possible and any(x is not None for x in full_pattern):
            return full_pattern
    return None
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

pattern = find_pattern(key_partial)

if pattern:
    # Decrypt with recovered key pattern
    res = []
    for i in range(len(ct)):
        k = pattern[i % len(pattern)]
        if k is not None:
            res.append(chr(ct[i] ^ k))
        else:
            res.append('?')
    print("".join(res))

Decryption Result

Success is a journey, not a destination. Every small step you take brings 
you closer to your goals. Stay focused, work hard, and never give up, even 
when challenges arise. Learn from failures, adapt, and keep moving forward. 
Surround yourself with positive people who inspire you. Believe in your 
potential, and you'll achieve greatness. Time is precious-use it wisely. 
Dream big, act now, and create the future you desire. Consistency and 
patience are key. Remember, progress takes effort, but every effort counts. 
Stay motivated, and success will follow! Flag is: CODEBY{REDACTED}

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

Theory

Known-Plaintext Attack on XOR

XOR encryption has the property:

C = P ⊕ K  →  K = C ⊕ P

If part of the plaintext is known, the corresponding key bytes can be recovered.

Repeating Key Detection

With a repeating key of length L:

key[i] = key[i mod L]

By collecting enough key bytes from different positions, the full key can be recovered if the known positions cover all L positions in the cycle.

Alternative Approaches

  1. Frequency analysis — if plaintext is in English, spaces and common letters can be guessed
  2. Crib dragging — if plaintext fragments are known (e.g., "flag{")
  3. Kasiski examination — to determine key length by repeating n-grams in ciphertext ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Key Takeaways / Lessons

  • Mastering Key recovery from partial plaintext, Known-plaintext attack on XOR cipher, Repeating key pattern detection was key to this challenge.
  • Always check for common misconfigurations and verify assumptions.

Crafted by XESXOR Research • 2025-12-25 • CUSTOM • Поврежденная расшифровка (Corrupted Decryption) • Difficulty: Easy