Harder encryptor
Harder encryptor
Platform: spbctf | Category: Crypto | Type: Challenge | Difficulty: Medium | OS: NA | Author: XESXOR | Date: 2026-03-09 | Status: Solved Techniques: iterative_xor_reversal, xor_parity_analysis
Summary
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 plaintext.
Harder encryptor — CryptoKids 2.0
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:
- Starts by XORing the first character
- Iteratively XORs a growing prefix with the key
- 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:
- Determine the number of XOR operations for each position
- Check the parity of that number
- If odd — XOR the encrypted byte with the key
- If even — the byte is already the original flag character
python read-only • copy allowed#!/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}")