defpct_join(bs): return"".join("%%%02x" % (b & 0xff) for b in bs)
defmain(): # Part 1: exhaustive listing for a in final_string: oa = ord(a) for i in allowed: oi = ord(i) for p in allowed: op = ord(p) if (oi ^ op) == oa: print(f"i={hex0(oi)} p={hex0(op)} a={hex0(oa)}")
def find_subs(base_chars, target_chars): base_codes = [o(c) for c in base_chars] # 预建 2 元、3 元查表:值->(x,y, [z]) table2 = {} for x, y in product(base_codes, repeat=2): table2.setdefault(x ^ y, []).append((x, y)) table3 = {} for x, y, z in product(base_codes, repeat=3): table3.setdefault(x ^ y ^ z, []).append((x, y, z))
subs2, subs3 = {}, {} for t in target_chars: ot = o(t) if ot in table2: subs2[t] = [(chr(x), chr(y)) for x, y in table2[ot]] if ot in table3: subs3[t] = [(chr(x), chr(y), chr(z)) for x, y, z in table3[ot]] return subs2, subs3
# 打印每个目标字符的部分替代方案(避免过长,这里各列举最多 6 条) LIM = 6 print("\n== 2-term XOR (t = x ^ y), up to 6 examples ==") for t in uniq: if t in subs2: ex = " , ".join(f"{a}^{b}"for a, b in subs2[t][:LIM]) print(f" {repr(t)}: {ex}")
print("\n== 3-term XOR (t = x ^ y ^ z), up to 6 examples ==") for t in uniq: if t in subs3: ex = " , ".join(f"{a}^{b}^{c}"for a, b, c in subs3[t][:LIM]) print(f" {repr(t)}: {ex}")
# 可移除性:把某个字符从“可用材料”里剔除后,能否由剩余 base 合成它? print("\n== Removability check (can t be rebuilt from BASE without using t and forbidden?) ==") for t in uniq: # 这个检查的语义:我们想“删掉 t 这个字面字符”,看看还能不能用剩余 base 合成 t reduced_base = sorted((set(base) - {t})) s2, s3 = find_subs(reduced_base, [t]) ok = (t in s2) or (t in s3) print(f" remove {repr(t)} ? {'YES (rebuildable)' if ok else 'NO'}")