MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / primitive_root

Function primitive_root

ciphers/elgamal_key_generator.py:16–24  ·  view source on GitHub ↗
(p_val: int)

Source from the content-addressed store, hash-verified

14# Handbook of Applied Cryptography(CRC Press, ISBN : 0-8493-8523-7, October 1996)
15# and it seems to run nicely!
16def primitive_root(p_val: int) -> int:
17 print("Generating primitive root of p")
18 while True:
19 g = random.randrange(3, p_val)
20 if pow(g, 2, p_val) == 1:
21 continue
22 if pow(g, p_val, p_val) == 1:
23 continue
24 return g
25
26
27def generate_key(key_size: int) -> tuple[tuple[int, int, int, int], tuple[int, int]]:

Callers 1

generate_keyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected