← Back to Writeups
CUSTOMMediumCrypto

TTP — Two-Time Pad

XESXOR9/10/20261 min read
#crypto#custom#medium#otp_reuse_attack#two_time_pad_attack

TTP — Two-Time Pad

Platform: spbctf | Category: Crypto | Type: Challenge | Difficulty: Medium | OS: NA | Author: XESXOR | Date: 2026-03-08 | Status: Solved Techniques: otp_reuse_attack, two_time_pad_attack

Summary

Task: Two ciphertexts encrypted with OTP using the same key, one known plaintext. Solution: Two-Time Pad attack - recover key by XORing known plaintext with its ciphertext, then decrypt the second message.

TTP — Crypto Kids 2.0

Description

"Looks like OTP, but 🤔". Two ciphertexts with same key, one known plaintext.

Analysis

Two-Time Pad attack: when OTP (One-Time Pad) is used twice with the same key, security is completely lost.

If C1 = P1 ⊕ K and C2 = P2 ⊕ K, then:

  • C1 ⊕ C2 = P1 ⊕ P2
  • Knowing P1, we can find K = C1 ⊕ P1
  • Then P2 = C2 ⊕ K

Solution

python
#!/usr/bin/env python3
# Given:
# C1 - first ciphertext
# C2 - second ciphertext  
# P1 = "good_morning_mister_Bond" - known plaintext
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

def xor_bytes(a, b):
    return bytes(x ^ y for x, y in zip(a, b))

# From the task file
c1 = bytes.fromhex("...")  # first ciphertext
c2 = bytes.fromhex("...")  # second ciphertext
p1 = b"good_morning_mister_Bond"

# Recover the key
key = xor_bytes(c1, p1)

# Decrypt the second message
p2 = xor_bytes(c2, key)
print(p2.decode())
# Output: spbctf{REDACTED}

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