Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Created July 10, 2022 13:37
Show Gist options
  • Save HirbodBehnam/b870749ae3b213c5128fc813bc539f45 to your computer and use it in GitHub Desktop.
Save HirbodBehnam/b870749ae3b213c5128fc813bc539f45 to your computer and use it in GitHub Desktop.
Cycle finder for discrete logarithm problem
def find_cyclic(p, g) -> int:
seen = set()
current = g
while True:
current *= g
current %= p
if current in seen:
print(sorted(seen))
print(len(seen))
return len(seen)
seen.add(current)
#find_cyclic(1971, 2)
#exit()
l = list()
for i in range(1501, 2000, 2):
l.append((i, find_cyclic(i, 2)))
l.sort(key=lambda x: x[1])
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment