Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/sage/groups/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,14 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
ord = integer_ring.ZZ(ord)
try:
if ord == Infinity:
return bsgs(base, a, bounds, identity=identity, inverse=inverse, op=op, operation=operation)
if algorithm == 'bsgs':
return bsgs(base, a, bounds, identity=identity, inverse=inverse, op=op, operation=operation)
elif algorithm == 'lambda':
return discrete_log_lambda(base, a, bounds, inverse=inverse, identity=identity, op=op, operation=operation)
elif algorithm == 'rho':
raise ValueError('pollard rho algorithm does not work with infinite order elements')
else:
raise ValueError(f"unknown algorithm {algorithm}")
if base == power(base, 0) and a != base:
raise ValueError
f = ord.factor()
Expand Down Expand Up @@ -984,6 +991,8 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
c = discrete_log_rho(h, gamma, ord=pi, inverse=inverse, identity=identity, op=op, operation=operation)
elif algorithm == 'lambda':
c = discrete_log_lambda(h, gamma, (0, temp_bound), inverse=inverse, identity=identity, op=op, operation=operation)
else:
raise ValueError(f"unknown algorithm {algorithm}")
l[i] += c * (pi**j)
running_bound //= pi
running_mod *= pi
Expand Down Expand Up @@ -1100,14 +1109,14 @@ def discrete_log_lambda(a, base, bounds, operation='*', identity=None, inverse=N
c += r
if mut:
H.set_immutable()
mem = {H}
mem = H
# second random walk
H = a
d = 0
while c - d >= lb:
if mut:
H.set_immutable()
if ub >= c - d and H in mem:
if ub >= c - d and H == mem:
return c - d
r, e = M[hash_function(H) % k]
H = mult(H, e)
Expand Down
Loading