← Back to Writeups
CUSTOMMediumCrypto

Harder encryptor

XESXOR9/2/20262 min read
#crypto#custom#medium#iterative_xor_reversal#xor_parity_analysis

Harder encryptor

Platform: CUSTOM | Category: Crypto | Type: Challenge | Difficulty: Medium | OS: N/A | **Author: XESXOR Techniques: iterative_xor_reversal, xor_parity_analysis

Summary

Walkthrough of the CUSTOM Crypto Harder encryptor. Task: Iterative XOR encryption with known key where each position is XORed a different number of times. Solution: Track XOR parity per position - odd count means XOR with key, even count means plainte

Description

Given an encryption script that iteratively XORs flag bytes with a known key. Key: key_with_the_same_length_maybe_little_bit_more_hue_hue_hue.

Analysis

The encryption algorithm works as follows:

  1. Starts by XORing the first character
  2. Iteratively XORs a growing prefix with the key
  3. Each position is XORed a specific number of times:
    • Position 0 → (n-2) times
    • Position j → (n-1-j) times

Key observation: if the number of XOR operations for a position is odd, then the final value = flag_char XOR key_char. If even — the final value equals the original flag character (XOR with itself gives 0). ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Solution

To decode we need to:

  1. Determine the number of XOR operations for each position
  2. Check the parity of that number
  3. If odd — XOR the encrypted byte with the key
  4. If even — the byte is already the original flag character
python
#!/usr/bin/env python3
"""
Harder encryptor solver - CryptoKids 2.0
Reverses iterative XOR encryption by tracking XOR parity per position
"""

def solve(ciphertext: bytes, key: bytes) -> str:
    """
    Decode iterative XOR cipher.
    
    For position j in string of length n:
    - XOR count = (n - 1 - j)
    - If odd: final = flag[j] ^ key[j]
    - If even: final = flag[j]
    """
    n = len(ciphertext)
    flag = []
    
    for j in range(n):
        xor_count = n - 1 - j
        
        if xor_count % 2 == 1:  # Odd - need to XOR with key
            flag_char = ciphertext[j] ^ key[j % len(key)]
        else:  # Even - already plaintext
            flag_char = ciphertext[j]
        
        flag.append(chr(flag_char))
    
    return ''.join(flag)
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍


if __name__ == "__main__":
    key = b"key_with_the_same_length_maybe_little_bit_more_hue_hue_hue"
    
    # Read ciphertext from file or use provided encrypted data
    with open("encrypted.bin", "rb") as f:
        ciphertext = f.read()
    
    flag = solve(ciphertext, key)
    print(f"Flag: {flag}")

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

Key Takeaways / Lessons

  • Mastering iterative_xor_reversal, xor_parity_analysis was key to this challenge.
  • Always check for common misconfigurations and verify assumptions.

Crafted by XESXOR Research • 2026-03-09 • CUSTOM • Harder encryptor • Difficulty: Medium