W1seGuy — TryHackMe Write-Up

· prosetesting's blog

Known Plaintext Attack on short-key XOR encryption. Easy Crypto challenge from TryHackMe.

Table of Contents

W1seGuy #

🏴 Platform: TryHackMe
🔬 Category: Crypto (XOR)
🟢 Difficulty: Easy
📅 Date: 2026-02-12
✍️ Author: tonton
⏱️ Reading time: ~2 min

Reconnaissance #

The server sends an XOR-encrypted text in hexadecimal and asks for the encryption key.

Source code analysis (source-1705339805281.py):

Key insight: the flag always starts with THM{ — that's our known plaintext.

Exploitation #

Concept: Known Plaintext Attack on XOR #

The fundamental property of XOR:

plaintext XOR key = ciphertext
ciphertext XOR plaintext = key

By knowing THM{ (4 chars), we directly recover 4 out of 5 key characters. The 5th one is brute-forced over ~62 possibilities.

Exploit Script #

 1import string
 2
 3cipher = bytes.fromhex("<hex received from server>")
 4
 5# Recover the first 4 key chars via known plaintext
 6known = "THM{"
 7key = ""
 8for i in range(4):
 9    key += chr(cipher[i] ^ ord(known[i]))
10
11# Brute-force the 5th character
12for c in string.ascii_letters + string.digits:
13    test_key = key + c
14    result = ""
15    for i in range(len(cipher)):
16        result += chr(cipher[i] ^ ord(test_key[i % 5]))
17    if result.endswith("}"):
18        print(f"Key: {test_key}")
19        print(f"Flag: {result}")
20        break

Execution #

Connection 1 — ciphertext: 607e3a2d3f...

Connection 2 — ciphertext: 3a22172f33...

Flag #

Tools Used #

What Didn't Work #

Lessons Learned #

last updated:
⬛⚪⬛
⬛⬛⚪  ☠ user
⚪⚪⚪  rm -rf /ignorance && echo 42 > /dev/brain