Lost in Parity

I deleted the flag.
python3 xor.py ./f* > xor
rm xor.py flag.txt
Author: @miko

Category: misc

Solver: frcroth, mp455

Flag: ENO{R41D1NG_F1L3S_4R3_W3?}

The challenge gives us a bunch of files - 255 files and the xor-file. A quick random sample of wc -c suggests that all files including the xor-file have the same size: 26 bytes.

The challenge description hints that the xor-file might be the result of applying the xor-operation to the 255 files and the flag.txt. Due to the associativity of the xor-operation, we can simplify the calculation to files ⊕ flag = xor with files being the xor-result of all files (except the xor-file). Because the inverse element for the xor-operation is the element itself, we can calculate the flag as flag = files ⊕ xor.

With this idea in mind, we can write a simple Python script that calculates the flag:

import sys
from os import listdir
from os.path import isfile, join

files = []
data_path = "./data/"
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))]
last_xor = None

for f in onlyfiles:
	if last_xor is None:
		last_xor = bytearray(open(data_path + f, 'rb').read())
		continue
	else:
		next_f = bytearray(open(data_path + f, 'rb').read())
		xor_result = last_xor
		for i in range(len(next_f)):
			xor_result[i] = last_xor[i] ^ next_f[i]
			last_xor = xor_result

open("flag.txt", 'wb').write(last_xor)

Indeed, the calculated flag.txt contains the flag.