← Back to Writeups
CUSTOMEasyCrypto

Туда-сюда

XESXOR9/10/20262 min read
#crypto#custom#easy#xor_reversal

Туда-сюда

Platform: duckerz | Category: Crypto | Type: Challenge | Difficulty: Easy | OS: NA | Author: XESXOR | Date: 2026-01-09 | Status: Solved Techniques: xor_reversal

Summary

Task: XOR cipher where each character is XORed with its position index. Solution: Apply the same XOR operation to ciphertext since XOR is self-inverse.

Туда-сюда — duckerz CTF

Description

"Туда - сюда, туда — сюда.… и ведь ничего не меняется" (Translation: "Back and forth, back and forth... and nothing changes")

Files: crypt2.zip (crypt2.py, output)

Analysis

Encryption script (crypt2.py)

python
from math import *

print('Enter the messsage: ')
message = input()
output = ''
for i in range(len(message)):
    output += chr(ord(message[i])^i)

print(output, "GLHF")

Encrypted data (output)

b'DTAHAW\|p9xT=8Qa &Mw%sP&{Lv,C~/o\x13S_'

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

Vulnerability

The encryption uses XOR of each character with its position index:

  • output[i] = message[i] ^ i

Key property of XOR: the operation is symmetric and reversible!

  • A ^ B = C means C ^ B = A
  • Applying the same operation to ciphertext recovers the plaintext

The task name "Туда-сюда" (back and forth) is a direct hint at XOR reversibility.

Solution

python
#!/usr/bin/env python3
"""
duckerz CTF - Туда-сюда
XOR with index reversal
"""

# Encrypted data
encrypted = b'DTAHAW\|p9xT=8Qa &Mw%sP&{Lv,C~/o\x13S_'
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Decryption: apply the same XOR with index operation
decrypted = ''
for i in range(len(encrypted)):
    decrypted += chr(encrypted[i] ^ i)

print("Decrypted:", decrypted)
# Output: DUCKERZ{REDACTED}

Theory

XOR (exclusive OR) has the following properties:

  1. Commutativity: A ^ B = B ^ A
  2. Associativity: (A ^ B) ^ C = A ^ (B ^ C)
  3. Self-inverse: A ^ A = 0
  4. Identity element: A ^ 0 = A

From this follows: (A ^ B) ^ B = A - double application of XOR with the same key returns the original value. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Alternative one-liner

python
print(''.join(chr(b^i) for i,b in enumerate(b'DTAHAW\|p9xT=8Qa &Mw%sP&{Lv,C~/o\x13S_')))

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