


import os
import random
import sys

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



def        UpperCamelCase_(   )					->		None:
    print('Making key files...'				)
    make_key_files('rsa'							,				1024				)
    print('Key files generation successful.'				)



def        UpperCamelCase_(   lowerCamelCase_				)					->		tuple[tuple[int, int], tuple[int, int]]:
    print('Generating prime p...'				)
    _lowercase :							List[Any]   	=	rabinMiller.generate_large_prime(lowerCamelCase_				)
    print('Generating prime q...'				)
    _lowercase :							int   	=	rabinMiller.generate_large_prime(lowerCamelCase_				)
    _lowercase :							Tuple   	=	p * q

    print('Generating e that is relatively prime to (p - 1) * (q - 1)...'				)
    while True:
        _lowercase :							Tuple   	=	random.randrange(2 ** (key_size - 1)							,				2 ** (key_size)				)
        if cryptoMath.gcd(lowerCamelCase_							,				(p - 1) * (q - 1)				) == 1:
            break

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

    _lowercase :							Optional[Any]   	=	(n, e)
    _lowercase :							List[Any]   	=	(n, d)
    return (public_key, private_key)



def        UpperCamelCase_(   lowerCamelCase_							,				lowerCamelCase_				)					->		None:
    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()

    _lowercase :							List[str]   	=	generate_key(lowerCamelCase_				)
    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()






# this script reports modified .py files under the desired list of top-level sub-dirs passed as a list of arguments, e.g.:
#   python ./utils/get_modified_files.py utils src tests examples
#
# it uses git to find the forking point and which files were modified - i.e. files not under git won't be considered
# since the output of this script is fed into Makefile commands it doesn't print a newline after the results

import re
import subprocess
import sys


SCREAMING_SNAKE_CASE :   List[Any]							      =				subprocess.check_output("git merge-base main HEAD".split()).decode("utf-8")
SCREAMING_SNAKE_CASE :   Optional[int]							      =				(
    subprocess.check_output(F"git diff --diff-filter=d --name-only {fork_point_sha}".split()).decode("utf-8").split()
)

SCREAMING_SNAKE_CASE :   Any							      =				"|".join(sys.argv[1:])
SCREAMING_SNAKE_CASE :   Union[str, Any]							      =				re.compile(rF"^({joined_dirs}).*?\.py$")

SCREAMING_SNAKE_CASE :   List[Any]							      =				[x for x in modified_files if regex.match(x)]
print(" ".join(relevant_modified_files), end="")


