"""Check the literal prime-power iteration described in Guo2017 Lemma B.1.""" import json def order(x, p): y = 1 for n in range(1, p): y = y*x % p if y == 1: return n raise ValueError("nonunit") p, ell, x, y = 19, 3, 4, 9 assert order(x, p) == order(y, p) == 9 assert pow(x, 4, p) == y states = [] current = x seen = set() while current not in seen: seen.add(current) candidates = [pow(current, k, p) for k in range(ell)] states.append({"base": current, "candidates": candidates, "differences_mod_p": [(v-y) % p for v in candidates]}) assert y not in candidates current = pow(current, ell, p) result = { "source": "Guo2017 thesis printed p240 LemmaB.1; PDFp247", "p": p, "ell": ell, "x": x, "y": y, "orders": [9, 9], "known_discrete_log": 4, "states": states, "repeat_base": current, "literal_iteration_fails": True, } print(json.dumps(result, indent=2))