Reversibility (Обратимость)
Reversibility (Обратимость)
Platform: CUSTOM | Category: Crypto | Type: Challenge | Difficulty: Easy | OS: N/A | **Author: XESXOR Techniques: key_recovery, xor_properties
Summary
Walkthrough of the CUSTOM Crypto Reversibility (Обратимость). Task: Given XOR equations (key1, key1^key2, key2^key3, flag^key1^key2^key3). Solution: Use XOR reversibility and associativity properties to recover keys sequentially and decrypt the flag.
Description
"Для изучения симметричных алгоритмтов шифрования полезно знать как работает xor)."
(Translation: "To study symmetric encryption algorithms, it's useful to know how XOR works).")
Files: reversibility.txt
key1: 21af7f08b2152df088a5e72226c447d4d0d964bb46f0845b3f39f578b9748bd4440e17d04a20c0f4
key1 ^ key2: 9600e25b79ba3b5543adaad720a0343f6d1be23c7e5f95915f2f0835c4c74a8a0bb717ec6ff1d3f5
key2 ^ key3: cf27c4d4319805747929c7e9f758f3e4160b3fffa83b2b3ab0c689fb98273585b4cc534a6aabd384
flag ^ key1 ^ key3 ^ key2: aaddf897c6df72ffc5ff53fbb2ad8044f7a46a3097949b0feba00eb05760cc22c1a075f611ff6a0d
Analysis
The task demonstrates two fundamental properties of the XOR operation:
1. Reversibility
A ^ B ^ B = A
XOR is a self-inverse operation. Applying the same value twice cancels the effect.
2. Associativity
(A ^ B) ^ C = A ^ (B ^ C)
The order of grouping operations does not affect the result.
Solution Plan
Given:
key1key1 ^ key2key2 ^ key3flag ^ key1 ^ key3 ^ key2
We can sequentially recover all keys:
- Get key2:
key2 = key1 ^ (key1 ^ key2) - Get key3:
key3 = key2 ^ (key2 ^ key3) - Get flag:
flag = (flag ^ key1 ^ key3 ^ key2) ^ key1 ^ key2 ^ key3
Solution
python read-only • copy allowed#!/usr/bin/env python3 """ Duckerz CTF - Reversibility XOR key recovery challenge """ # Data from file key1 = bytes.fromhex("21af7f08b2152df088a5e72226c447d4d0d964bb46f0845b3f39f578b9748bd4440e17d04a20c0f4") key1_xor_key2 = bytes.fromhex("9600e25b79ba3b5543adaad720a0343f6d1be23c7e5f95915f2f0835c4c74a8a0bb717ec6ff1d3f5") key2_xor_key3 = bytes.fromhex("cf27c4d4319805747929c7e9f758f3e4160b3fffa83b2b3ab0c689fb98273585b4cc534a6aabd384") flag_xor_keys = bytes.fromhex("aaddf897c6df72ffc5ff53fbb2ad8044f7a46a3097949b0feba00eb05760cc22c1a075f611ff6a0d") # Step 1: Recover key2 # key2 = key1 ^ (key1 ^ key2) key2 = bytes(a ^ b for a, b in zip(key1, key1_xor_key2)) # Step 2: Recover key3 # key3 = key2 ^ (key2 ^ key3) key3 = bytes(a ^ b for a, b in zip(key2, key2_xor_key3)) # Step 3: Recover flag # flag = (flag ^ key1 ^ key2 ^ key3) ^ key1 ^ key2 ^ key3 step1 = bytes(a ^ b for a, b in zip(flag_xor_keys, key1)) step2 = bytes(a ^ b for a, b in zip(step1, key2)) flag = bytes(a ^ b for a, b in zip(step2, key3)) print(f"Flag: {flag.decode()}")
Alternative Solution (one-liner)
python read-only • copy allowedfrom functools import reduce from operator import xor def xor_bytes(*args): return bytes(reduce(xor, x) for x in zip(*args)) flag = xor_bytes(flag_xor_keys, key1, key2, key3)
Theory
XOR Properties
| Property | Formula | Description |
|---|---|---|
| Commutativity | A ^ B = B ^ A | Order of operands doesn't matter |
| Associativity | (A ^ B) ^ C = A ^ (B ^ C) | Order of grouping doesn't matter |
| Self-inverse | A ^ A = 0 | XOR with itself gives 0 |
| Identity element | A ^ 0 = A | XOR with zero doesn't change the value |
| Reversibility | A ^ B ^ B = A | Double XOR cancels out |
| |
Why This Works
flag ^ key1 ^ key2 ^ key3 (encrypted)
^ key1 (cancel key1)
^ key2 (cancel key2)
^ key3 (cancel key3)
= flag (get the flag)
Difficulty Level
Easy — basic task on understanding XOR properties. Ideal for beginners in cryptography.
Key Takeaways / Lessons
- Mastering key_recovery, xor_properties was key to this challenge.
- Always check for common misconfigurations and verify assumptions.
Crafted by XESXOR Research • 2026-01-09 • CUSTOM • Reversibility (Обратимость) • Difficulty: Easy