





import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

A    :					List[str] =      3







def    __lowerCamelCase					(							__a   :Any    )		->				int:






		"""simple docstring"""

		print("""Generating primitive root of p"""    )
		while True:
				A__        =   random.randrange(3    ,     lowerCAmelCase_    )
				if pow(lowerCAmelCase_    ,     2    ,     lowerCAmelCase_    ) == 1:
						continue
				if pow(lowerCAmelCase_    ,     lowerCAmelCase_    ,     lowerCAmelCase_    ) == 1:
						continue
				return g







def    __lowerCamelCase					(							__a   :List[str]    )		->				tuple[tuple[int, int, int, int], tuple[int, int]]:






		"""simple docstring"""

		print("""Generating prime p..."""    )
		A__        =   rabin_miller.generate_large_prime(lowerCAmelCase_    )  # select large prime number.
		A__        =   primitive_root(lowerCAmelCase_    )  # one primitive root on modulo p.
		A__        =   random.randrange(3    ,     lowerCAmelCase_    )  # private_key -> have to be greater than 2 for safety.
		A__        =   cryptomath.find_mod_inverse(pow(lowerCAmelCase_    ,     lowerCAmelCase_    ,     lowerCAmelCase_    )    ,     lowerCAmelCase_    )

		A__        =   (key_size, e_a, e_a, p)
		A__        =   (key_size, d)

		return public_key, private_key







def    __lowerCamelCase					(							__a   :Tuple    ,     __a   :List[str]    )		->				None:






		"""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()

		A__        =   generate_key(lowerCAmelCase_    )
		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    __lowerCamelCase					(							)		->				None:






		"""simple docstring"""

		print("""Making key files..."""    )
		make_key_files("""elgamal"""    ,     2_0_4_8    )
		print("""Key files generation successful"""    )


if __name__ == "__main__":
					main()








'''simple docstring'''

import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


__lowerCAmelCase									=   logging.getLogger()

@unittest.skip('Temporarily disable the doc tests.'   )
@require_torch
@require_tf
@slow
class 	__magic_name__						(    unittest.TestCase   ):







							def 							__lowercase			(							self					:       str	,_UpperCAmelCase					:       Path	,_UpperCAmelCase					:       Union[str, None] = None	,_UpperCAmelCase					:       Union[List[str], None] = None	,_UpperCAmelCase					:       Union[str, List[str], None] = None	,_UpperCAmelCase					:       bool = True	,):
									_a     :      Dict        =							[file for file in os.listdir(_UpperCAmelCase		) if os.path.isfile(os.path.join(_UpperCAmelCase	,_UpperCAmelCase		)		)]

									if identifier is not None:
											_a     :      str        =							[file for file in files if identifier in file]

									if n_identifier is not None:
											if isinstance(_UpperCAmelCase	,_UpperCAmelCase		):
													for n_ in n_identifier:
															_a     :      int        =							[file for file in files if n_ not in file]
											else:
													_a     :      Optional[Any]        =							[file for file in files if n_identifier not in file]

									_a     :      Dict        =							ignore_files or []
									ignore_files.append('__init__.py'		)
									_a     :      List[str]        =							[file for file in files if file not in ignore_files]

									for file in files:
											# Open all files
											print('Testing'	,_UpperCAmelCase		)

											if only_modules:
													_a     :      Any        =							file.split('.'		)[0]
													try:
															_a     :      Optional[int]        =							getattr(_UpperCAmelCase	,_UpperCAmelCase		)
															_a     :      Dict        =							doctest.DocTestSuite(_UpperCAmelCase		)
															_a     :      Optional[int]        =							unittest.TextTestRunner().run(_UpperCAmelCase		)
															self.assertIs(len(result.failures		)	,0		)
													except AttributeError:
															logger.info(F"""{module_identifier} is not a module."""		)
											else:
													_a     :      str        =							doctest.testfile(str('..' / directory / file		)	,optionflags=doctest.ELLIPSIS		)
													self.assertIs(result.failed	,0		)







							def 							__lowercase			(							self					:       Union[str, Any]		):
									_a     :      Optional[Any]        =							Path('src/transformers'		)
									_a     :      Optional[Any]        =							'modeling'
									_a     :      Union[str, Any]        =							[
									    'modeling_ctrl.py',
									    'modeling_tf_ctrl.py',
									]
									self.analyze_directory(_UpperCAmelCase	,identifier=_UpperCAmelCase	,ignore_files=_UpperCAmelCase		)







							def 							__lowercase			(							self					:       int		):
									_a     :      str        =							Path('src/transformers'		)
									_a     :      List[str]        =							'tokenization'
									self.analyze_directory(_UpperCAmelCase	,identifier=_UpperCAmelCase		)







							def 							__lowercase			(							self					:       int		):
									_a     :      Any        =							Path('src/transformers'		)
									_a     :      str        =							'configuration'
									self.analyze_directory(_UpperCAmelCase	,identifier=_UpperCAmelCase		)







							def 							__lowercase			(							self					:       Dict		):
									_a     :      Tuple        =							Path('src/transformers'		)
									_a     :      Optional[int]        =							['configuration', 'modeling', 'tokenization']
									self.analyze_directory(_UpperCAmelCase	,n_identifier=_UpperCAmelCase		)







							def 							__lowercase			(							self					:       Optional[Any]		):
									_a     :      Union[str, Any]        =							Path('docs/source'		)
									_a     :      List[str]        =							['favicon.ico']
									self.analyze_directory(_UpperCAmelCase	,ignore_files=_UpperCAmelCase	,only_modules=_UpperCAmelCase		)




