Rating:

```
#
# If we assume that we already know secrets 1..R-1, and we have (L,R,V) test interval ending at R,
# it is trivial to compute secret for R.
# secret[R] = xor( secret[L], ..., secret[R-1], V )
#
# We iteratively add tests to our data structure indexed by R.
#
# If there is already test ending at position R, it is possible to split the longer one into new, non-overlapping tests.
#

from pwn import *

p = remote("2020.redpwnc.tf", 31458)
# f = open("expohash.in", "r")

# read input
lines = 0
checks = []

while True:
line = p.readline()
l,r,c = line.strip().split()
checks.append( [int(l), int(r), int(c)] )
lines += 1
if lines == 100000:
break

checksums = dict()

def insert_interval(check):

while True:
if check[1] in checksums:
# print("Checksum index %d is already used." % check[1])
# print(check)
# print(checksums[check[1]])

prev = checksums[check[1]]
# find shorter one
if check[0] > prev[0]:
# new one is shorter, replace it for current index
checksums[check[1]] = check
# split previous one and re-insert it
new = prev[0], check[0]-1, prev[2] ^ check[2]
check = new
elif check[0] < prev[0]:
# previous one is shorter, split the new one
new = check[0], prev[0]-1, prev[2] ^ check[2]
check = new
else:
# print("Exact same interval?")
# print(prev)
# print(check)
assert prev[2] == check[2]
return False
else:
checksums[check[1]] = check
return True

for check in checks:
insert_interval(check)
print(len(checksums))

secret = {}
# lets generate secret integers
for i in range(1,100001):
# do we have checksum for this position?
if i in checksums:
c = 0
for j in range(checksums[i][0], i):
c = c ^ secret[j]
secret[i] = checksums[i][2] ^ c
else:
# no tests, just use any random number..
secret[i] = 0x1337
print(i, secret[i])
p.sendline( str(secret[i]) )

print(p.read())

# flag{1_g0t_th3_c0mb_thx}
```