diff --git a/algebre-non-lineaire/is_generator.py b/algebre-non-lineaire/is_generator.py new file mode 100755 index 0000000..97d5aef --- /dev/null +++ b/algebre-non-lineaire/is_generator.py @@ -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()