Tags: crypto 

Rating:

# Crypto: yORs Truly <3

> Author: shlswnt

> Description: I have encrypted some text but it seems I have lost the key! Can you find it?


> Unlock Hint for 0 points: A string of text can be decrypted by merely reapplying the XOR function with the key

[yors-truly.py](https://github.com/nopedawn/CTF/blob/main/WolvCTF24/Beginner-yORs-Truly/yors-truly.py)

Given th first chall crypto beginner, this is a classic XOR encryption problem. The plaintext is XORed with a key to get the ciphertext. If we lost the key but have the plaintext and the ciphertext, we can retrieve the key by XORing the plaintext and the ciphertext.

```python {title="yors-truly.py" lineNos=true lineNoStart=1}
import base64

plaintext = "A string of text can be encrypted by applying the bitwise XOR operator to every character using a given key"
key = "" # I have lost the key!

def byte_xor(ba1, ba2):
return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])

ciphertext_b64 = base64.b64encode(byte_xor(key.encode(), plaintext.encode()))

ciphertext_decoded = base64.b64decode("NkMHEgkxXjV/BlN/ElUKMVZQEzFtGzpsVTgGDw==")

print(ciphertext_decoded)
```

Here's how we can modify the code to find the key:

```python {title="solver.py" lineNos=true lineNoStart=1}
import base64

plaintext = "A string of text can be encrypted by applying the bitwise XOR operator to every character using a given key"

def byte_xor(ba1, ba2):
return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])

ciphertext_decoded = base64.b64decode("NkMHEgkxXjV/BlN/ElUKMVZQEzFtGzpsVTgGDw==")

key = byte_xor(plaintext.encode(), ciphertext_decoded)

print(key)
```

This will print the key that was used to encrypt the plaintext.

> Flag: `wctf{X0R_i5_f0rEv3r_My_L0Ve}`

Original writeup (https://nopedawn.github.io/posts/ctfs/2024/wolv-ctf-2024/#crypto-yors-truly-3).