defnext_state(state, b, i): state = (state + b + (i * 0x37 + 0xA5)) & MASK state = ((state >> 11) ^ rol32(state, 5)) & MASK return state
defenc(state, b): b ^= (state >> 8) & 0xFF b ^= state & 0xFF return (b + ((state >> 16) & 0xFF)) & 0xFF
deffinal_hash(key): h = 0x13579BDF for c in key: h = (rol32(h ^ c, 7) + 0x6D2B79F5) & MASK return h
solutions = []
defdfs(i, state, chosen): if i == len(IDX): solutions.append(chosen[:]) return for b inrange(256): s = next_state(state, b, i) if enc(s, b) == EXPECTED[i]: chosen.append(b) dfs(i + 1, s, chosen) chosen.pop()
dfs(0, 0xC0DEC0DE, [])
for chosen in solutions: key = bytearray(29) for i, b inenumerate(chosen): key[IDX[i]] = b if final_hash(key) == 0xEAB2F255: key = bytes(key) # 完整重放校验自检 state = 0xC0DEC0DE ok = True for i inrange(29): s = next_state(state, key[IDX[i]], i) if enc(s, key[IDX[i]]) != EXPECTED[i]: ok = False state = s assert ok and final_hash(key) == 0xEAB2F255 print('flag:', key.decode())