frncscrlnd's writeups

Writeups from challenges and CTFs i take part in.


Project maintained by frncscrlnd Hosted on GitHub Pages — Theme by mattgraham

Fixed XOR

In this challenge we need to write a script that decodes two strings from hex and XORs them together:

 Write a function that takes two equal-length buffers and produces their XOR combination.

If your function works properly, then when you feed it the string:

1c0111001f010100061a024b53535009181c

... after hex decoding, and when XOR'd against:

686974207468652062756c6c277320657965

... should produce:

746865206b696420646f6e277420706c6179

You can choose your preferred language for this, i chose Python. First we need to convert the strings from hex to raw bytes. bytes and fromhex() allow us to do just that:

a = "1c0111001f010100061a024b53535009181c"
a_bytes = bytes.fromhex(a)

It’s the same for the other string. Now onto the XOR part: we need to iterate through all of the strings’ characters and this means that we need a for loop that will execute for the number of characters the first string has.

for i in range(len(a_bytes)):
    x = a_bytes[i]
    y = b_bytes[i]
    result_list.append(x ^ y)

This section returns a list that has the result of XOR operation between the two strings. Now we need to turn it back into a hed:

result = bytes(result_list)
print(result.hex())

This will also print the resulting hex string.

Full code:

a = "1c0111001f010100061a024b53535009181c"
b = "686974207468652062756c6c277320657965"

a_bytes = bytes.fromhex(a)
b_bytes = bytes.fromhex(b)

result_list = []

for i in range(len(a_bytes)):
    x = a_bytes[i]
    y = b_bytes[i]
    result_list.append(x ^ y)

result = bytes(result_list)
print(result.hex())