efrei/algebre-non-lineaire/is_generator.py

35 lines
618 B
Python
Executable file

#!/usr/bin/env python3
"""In ElGamal cyclic systems, there is at least one generator.
Find out if a given number is a generator.
"""
def main() -> None:
"""Ask for p and g and calculate"""
p = int(input("p: "))
g = int(input("g: "))
print(is_generator(p, g))
def is_generator(p: int, g: int) -> bool:
"""Algorithm"""
family_size = 0
for i in range(1, p):
total = pow(g, i, p)
print(total)
if total == 1:
family_size = i
break
if family_size == p - 1:
return True
return False
if __name__ == "__main__":
main()