Add script is_generator.py
This commit is contained in:
parent
4b81f8123c
commit
6191293e03
1 changed files with 35 additions and 0 deletions
35
algebre-non-lineaire/is_generator.py
Executable file
35
algebre-non-lineaire/is_generator.py
Executable 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()
|
Loading…
Reference in a new issue