exclusive-oracle
**  
crypto  
cyberedu

Hey! Let's keep all of our secrets together, in the same place! That's awesome, you're so friendly! Narrator: He wasn't friendly...
This challenge provides an IP and a file from which we can see that the server is supposed to do.

import os

FLAG = ""
KEY = os.urandom(len(FLAG))
^
The key is generated with urandom. We cannot really just get the key by testing different key lengths


V Just a normal xor. The output xor is of the length of the bigger string and the smaller one is repeated
def xor(first, second):
    length = max(len(second), len(first))
    data = b''
    i, j = 0, 0
    for _ in range(length):
        data += (first[i] ^ second[j]).to_bytes(1, 'big')
        i += 1
        j += 1
        i %= len(first)
        j %= len(second)
        if i == 0 or j == 0:
            return data
    return data
if __name__ == "__main__":
V the flag is xored with the key
    secret = xor(FLAG, KEY)
    print("Just encrypted my flag. Encrypt your data too, and let's join them together!")
    data = input("Your data > ").encode()
V our input is also xored with the key
    print(secret + xor(data, KEY), sep="\n") --> the output will have the length of the flag + the length of the
data
    print(os.urandom(70))


I have made a simple python client to connect to the server
i=39
As = "a" *i

s = socket.socket()
s.connect(("34.89.210.219", 31338))
data = s.recv(1024).decode()
print(data)

s.send(As.encode())
s.send("\n".encode())
data = s.recv(1024)
s.send("\n".encode())

print(data.decode())

and tested the output with different values for my data (my data is As).
The length of the byte sequences was:
for i = 1 40 bytes
for i = 10 49 bytes
for i = 20 59 bytes
for i = 30 69 bytes
for i = 39 78 bytes
for i = 40 78 bytes
so for any i >= 39 the output is 78 bytes long.

the code from above:
secret = xor(FLAG, KEY)
print(secret + xor(data, KEY), sep="\n")
secret = first 39 bytes
The xor between
So, to get the flag I have to xor:
1. The last 39 bytes with my data to get the key
2. The first 39 bytes with the obtained key

The code:
As = "a" *39
data = b"\xd9\xef\xa4t\xd7\x91\x08\x9ez\x1a\x9a@<\x8d:\xdd]Q\x0c\xbf\x9d\x89\xa1\xd1\xefK\x01\xcbi\x9cq\xf5\xa8\x9a\xd6'<\x03o\xec\xc8\x86V\xe2\xb6\x12\x88sO\x8fR\x02\x983\x8fcG]\xac\x90\x8c\x9f\xc7\xbf^\x08\x9a}\xcaO\xa7\xa7\xca\xd0+i]s"
print("for i = 39:"+str(len(data)))

key=xor(data[39:], As.encode())
flag = xor(data[:39], key).decode()
print(flag)



TFCCTF{wh4ts_th3_w0rld_w1th0u7_3n1gm4?}