
'''simple docstring'''
import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812

def 						UpperCamelCase_     (	):
    """simple docstring"""






    print("Making key files..."       )
    make_key_files("rsa",		1_0_2_4       )
    print("Key files generation successful."       )

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
    """simple docstring"""






    print("Generating prime p..."       )
    snake_case_ :    Any     			=						rabinMiller.generate_large_prime(__snake_case       )
    print("Generating prime q..."       )
    snake_case_ :    Tuple     			=						rabinMiller.generate_large_prime(__snake_case       )
    snake_case_ :    Union[str, Any]     			=						p * q

    print("Generating e that is relatively prime to (p - 1) * (q - 1)..."       )
    while True:
        snake_case_ :    Any     			=						random.randrange(2 ** (key_size - 1),		2 ** (key_size)       )
        if cryptoMath.gcd(__snake_case,		(p - 1) * (q - 1)       ) == 1:
            break

    print("Calculating d that is mod inverse of e..."       )
    snake_case_ :    List[Any]     			=						cryptoMath.find_mod_inverse(__snake_case,		(p - 1) * (q - 1)       )

    snake_case_ :    Dict     			=						(n, e)
    snake_case_ :    Tuple     			=						(n, d)
    return (public_key, private_key)

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
    """simple docstring"""






    if os.path.exists(f'{name}_pubkey.txt'       ) or os.path.exists(f'{name}_privkey.txt'       ):
        print("\nWARNING:"       )
        print(
            f'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
            "Use a different name or delete these files and re-run this program."       )
        sys.exit()

    snake_case_			, snake_case_ :    Optional[Any]     			=						generate_key(__snake_case       )
    print(f'\nWriting public key to file {name}_pubkey.txt...'       )
    with open(f'{name}_pubkey.txt',		"w"       ) as out_file:
        out_file.write(f'{key_size},{public_key[0]},{public_key[1]}'       )

    print(f'Writing private key to file {name}_privkey.txt...'       )
    with open(f'{name}_privkey.txt',		"w"       ) as out_file:
        out_file.write(f'{key_size},{private_key[0]},{private_key[1]}'       )


if __name__ == "__main__":
      main()






'''simple docstring'''
from __future__ import annotations

from cmath import sqrt

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
    """simple docstring"""






    if a == 0:
        raise ValueError("Coefficient 'a' must not be zero."       )
    snake_case_ :    Union[str, Any]     			=						b * b - 4 * a * c

    snake_case_ :    List[str]     			=						(-b + sqrt(__SCREAMING_SNAKE_CASE       )) / (2 * a)
    snake_case_ :    int     			=						(-b - sqrt(__SCREAMING_SNAKE_CASE       )) / (2 * a)

    return (
        root_a.real if not root_a.imag else root_a,
        root_a.real if not root_a.imag else root_a,
    )

def 						UpperCamelCase_     (	):
    """simple docstring"""






    snake_case_			, snake_case_ :    str     			=						quadratic_roots(a=5,		b=6,		c=1       )
    print(f'The solutions are: {solutiona} and {solutiona}'       )


if __name__ == "__main__":
  main()




