#!/usr/bin/env python3 N=4 nr_tables=4 def gen_rainbow_reductors(k): def R1(x): return x / 10 * 10 + x % 3 def R2(x): return x / 10 * 10 % 3 + 3 def R3(x): return x / 10 * 10 % 3 + 6 def R4(x): return x / 10 * 10 + 9 Rint = [R1, R2, R3, R4] Rstr = [] for rint in Rint: Rstr.append(lambda s : str(int(rint(int(s, 10))) ^ k).zfill(N)) return Rstr def hashfn(s): return s[2:] + s[0:2] def chain_end(s, R): for r in R: s = r(hashfn(s)) return s def generate_table(f, R): v = [] for l in f: v.append([l, chain_end(l, R)]) return v def matches(k, v, needle, entry, R): start_string = entry[0] end_string = entry[1] s = start_string for i in range(0, k): s = R[i](hashfn(s)) return hashfn(s) == needle def gen_chain_from(needle, k, R): for i in range(k, len(R) - 1): needle = hashfn(R[i](needle)) return R[len(R)-1](needle)