#!/usr/local/bin/python3 import random; FLAG = open("flag.txt", "rb").read(); print("welcome to oooo") whileTrue: print(bytes(a^b for a, b inzip(FLAG, random.sample(range(0, 256), k=len(FLAG)))).hex() ifinput() != "exit"else exit())
quick idea
The server gives hex(flag XOR keystream). The keystream is made with random.sample(range(0, 256), k=len(FLAG)), so all bytes in one response are different.
We know the flag starts with corctf{ and ends with }.
Use the known bytes to figure out some keystream values. Then, remove any candidate bytes that would repeat the same keystream value in that response.
Repeat this process with many responses until each flag position has only one possible value.
can=[set(range(256))for _ inrange(flen)] for i,b inenumerate(pref): can[i]={b} can[-1]={ord('}')}
got=0 while got<lim andnotall(len(s)==1for s in can): conn.sendline() line=conn.recvline().strip().decode(errors='ignore') try: cipher=bytes.fromhex(line) except: continue iflen(cipher)!=flen: continue got+=1 ks_list=[] for p inrange(flen): iflen(can[p])==1: ks_list.append(cipher[p]^next(iter(can[p]))) for k in ks_list: for p inrange(flen): iflen(can[p])==1:continue bad={x for x in can[p] if (cipher[p]^x)==k} if bad:can[p]-=bad
ifall(len(s)==1for s in can): flag=bytes(next(iter(s))for s in can) print('flaggggggggggggg:',flag.decode())
conn.close()
result!
I kinda messed up the screenshot, but whatever lol.