Add script is_generator.py

This commit is contained in:
flyingscorpio@clevo 2022-03-01 15:22:58 +01:00
parent 4b81f8123c
commit 6191293e03

View file

@ -0,0 +1,35 @@
#!/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 = 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()