Commit f1101c04 authored by Christoph Conrads's avatar Christoph Conrads

Period length: improve code

* fix precondition checks
* return better upper bound estimate in some cases
parent c2ac35ce
......@@ -171,7 +171,7 @@ def factorize(kind, w, r, s, m):
assert 2 not in factors
factors[2] = s*w
elif w < 33:
elif w < 24:
factors = f(m)
else:
return None
......@@ -195,8 +195,11 @@ def compute_order_mod_m(a, k, m, ps):
assert m > a
assert isinstance(ps, dict)
if fractions.gcd(k, m) != 1:
raise ArithmeticError('gcd(k,m) != 1')
if fractions.gcd(a, m) != 1:
raise ArithmeticError('gcd(a,m) != 1')
if pow(a, k, m) != 1:
raise ArithmeticError('a^k mod m != 1')
k_0 = k
product = 1
......@@ -217,12 +220,12 @@ def compute_order_mod_m(a, k, m, ps):
assert product <= k_0
assert k_0 % product == 0
max_order = k
min_order = k
if k_0 == product:
return [k, k]
if k_0 != product:
div = k_0 // product
min_order = k // div
div = k_0 // product
min_order = k // div
max_order = min_order if pow(a, k // div, m) == 1 else k
return [min_order, max_order]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment