


import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__lowerCAmelCase	: Union[str, Any]  				=3


def        _UpperCamelCase							(      lowercase__      ):
						print('''Generating primitive root of p'''      )
						while True:
												__SCREAMING_SNAKE_CASE						:     Tuple					=		random.randrange(3    ,       lowercase__      )
												if pow(lowercase__    ,       2    ,       lowercase__      ) == 1:
																		continue
												if pow(lowercase__    ,       lowercase__    ,       lowercase__      ) == 1:
																		continue
												return g


def        _UpperCamelCase							(      lowercase__      ):
						print('''Generating prime p...'''      )
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		rabin_miller.generate_large_prime(lowercase__      )  # select large prime number.
						__SCREAMING_SNAKE_CASE						:     Dict					=		primitive_root(lowercase__      )  # one primitive root on modulo p.
						__SCREAMING_SNAKE_CASE						:     int					=		random.randrange(3    ,       lowercase__      )  # private_key -> have to be greater than 2 for safety.
						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		cryptomath.find_mod_inverse(pow(lowercase__    ,       lowercase__    ,       lowercase__      )    ,       lowercase__      )

						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		(key_size, e_a, e_a, p)
						__SCREAMING_SNAKE_CASE						:     str					=		(key_size, d)

						return public_key, private_key


def        _UpperCamelCase							(      lowercase__    ,       lowercase__      ):
						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()

						__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Tuple					=		generate_key(lowercase__      )
						print(F'''\nWriting public key to file {name}_pubkey.txt...'''      )
						with open(F'''{name}_pubkey.txt'''    ,       '''w'''      ) as fo:
												fo.write(F'''{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}'''      )

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


def        _UpperCamelCase							(      ):
						print('''Making key files...'''      )
						make_key_files('''elgamal'''    ,       2048      )
						print('''Key files generation successful'''      )


if __name__ == "__main__":
						main()




import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


__lowerCAmelCase	: Union[str, Any]  				={
    '<': operator.lt,
    '<=': operator.le,
    '==': operator.eq,
    '!=': operator.ne,
    '>=': operator.ge,
    '>': operator.gt,
}


def        _UpperCamelCase							(      lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__      ):
						if got_ver is None or want_ver is None:
												raise ValueError(
												    F'''Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider'''
												    F''' reinstalling {pkg}.'''      )
						if not ops[op](version.parse(lowercase__      )    ,       version.parse(lowercase__      )      ):
												raise ImportError(
												    F'''{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}'''      )


def        _UpperCamelCase							(      lowercase__    ,       lowercase__ = None      ):
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		F'''\n{hint}''' if hint is not None else ''''''

						# non-versioned check
						if re.match(R'''^[\w_\-\d]+$'''    ,       lowercase__      ):
												__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     str					=		requirement, None, None
						else:
												__SCREAMING_SNAKE_CASE						:     List[Any]					=		re.findall(R'''^([^!=<>\s]+)([\s!=<>]{1,2}.+)'''    ,       lowercase__      )
												if not match:
																		raise ValueError(
																		    '''requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but'''
																		    F''' got {requirement}'''      )
												__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Tuple					=		match[0]
												__SCREAMING_SNAKE_CASE						:     Optional[int]					=		want_full.split(''','''      )  # there could be multiple requirements
												__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		{}
												for w in want_range:
																		__SCREAMING_SNAKE_CASE						:     Any					=		re.findall(R'''^([\s!=<>]{1,2})(.+)'''    ,       lowercase__      )
																		if not match:
																								raise ValueError(
																								    '''requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,'''
																								    F''' but got {requirement}'''      )
																		__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Tuple					=		match[0]
																		__SCREAMING_SNAKE_CASE						:     List[Any]					=		want_ver
																		if op not in ops:
																								raise ValueError(F'''{requirement}: need one of {list(ops.keys()      )}, but got {op}'''      )

    # special case
						if pkg == "python":
												__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''.'''.join([str(lowercase__      ) for x in sys.version_info[:3]]      )
												for op, want_ver in wanted.items():
																		_compare_versions(lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__      )
												return

						# check if any version is installed
						try:
												__SCREAMING_SNAKE_CASE						:     Optional[int]					=		importlib.metadata.version(lowercase__      )
						except importlib.metadata.PackageNotFoundError:
												raise importlib.metadata.PackageNotFoundError(
												    F'''The \'{requirement}\' distribution was not found and is required by this application. {hint}'''      )

						# check that the right version is installed if version number or a range was provided
						if want_ver is not None:
												for op, want_ver in wanted.items():
																		_compare_versions(lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__      )


def        _UpperCamelCase							(      lowercase__      ):
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		'''Try: pip install transformers -U or pip install -e \'.[dev]\' if you\'re working with git main'''
						return require_version(lowercase__    ,       lowercase__      )
