Tags: crypto xor
Rating:
Description:
> We are exclusive -- you can't date anyone, not even the past! And don't even think about looking in the mirror!
We are given two files to download:
output.txt, which contains two lines:
```
xorrox=[1, 209, 108, 239, 4, 55, 34, 174, 79, 117, 8, 222, 123, 99, 184, 202, 95, 255, 175, 138, 150, 28, 183, 6, 168, 43, 205, 105, 92, 250, 28, 80, 31, 201, 46, 20, 50, 56]
enc=[26, 188, 220, 228, 144, 1, 36, 185, 214, 11, 25, 178, 145, 47, 237, 70, 244, 149, 98, 20, 46, 187, 207, 136, 154, 231, 131, 193, 84, 148, 212, 126, 126, 226, 211, 10, 20, 119]
```
and
xorrox.py - which contains the following code:
```
#!/usr/bin/env python3
import random
with open("flag.txt", "rb") as filp:
flag = filp.read().strip()
key = [random.randint(1, 256) for _ in range(len(flag))]
xorrox = []
enc = []
for i, v in enumerate(key):
k = 1
for j in range(i, 0, -1):
k ^= key[j]
xorrox.append(k)
enc.append(flag[i] ^ v)
with open("output.txt", "w") as filp:
filp.write(f"{xorrox=}\n")
filp.write(f"{enc=}\n")
```
Reading through the code we can see the following:
- an array with a size the length of our flag, being generated with random integers between 1 and 256. This range is representing the 256 characters in a 8-bit ascii character set.
- two arrays initialized: `xorrox[]` and `enc[]`
- loop through our new array of keys
- loop starting at our key integer value and go backwards 1 (ie. previous key)
- xor k and our key at position[j] of our keys
- append the key that has been xorred
- xor the integer value at position i of our flag with key at position i (v)
This might seem complicated, but it's pretty simple. We basically need to loop through our `xorrox` array, xor the value at position i with value of previous position. We have a "crib" of `flag{`, so we can skip positions 0-4.
```
#!/usr/bin/env python3
xorrox=[1, 209, 108, 239, 4, 55, 34, 174, 79, 117, 8, 222, 123, 99, 184, 202, 95, 255, 175, 138, 150, 28, 183, 6, 168, 43, 205, 105, 92, 250, 28, 80, 31, 201, 46, 20, 50, 56]
enc=[26, 188, 220, 228, 144, 1, 36, 185, 214, 11, 25, 178, 145, 47, 237, 70, 244, 149, 98, 20, 46, 187, 207, 136, 154, 231, 131, 193, 84, 148, 212, 126, 126, 226, 211, 10, 20, 119]
flag = 'flag{' # flag{ is our known text AKA "crib"
for i in range(5, len(xorrox)):
key = xorrox[i] ^ xorrox[i-1]
flag += chr(enc[i] ^ key)
print(flag)
```
`flag{21571dd4764a52121d94deea22214402}`