(p_val: int)
| 14 | # Handbook of Applied Cryptography(CRC Press, ISBN : 0-8493-8523-7, October 1996) |
| 15 | # and it seems to run nicely! |
| 16 | def 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 | |
| 27 | def generate_key(key_size: int) -> tuple[tuple[int, int, int, int], tuple[int, int]]: |