






import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

_UpperCAmelCase			:		Dict   				=    3





def 	lowerCAmelCase_		(lowercase__						:       int       )		->    int:


				'''simple docstring'''




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





def 	lowerCAmelCase_		(lowercase__						:       int       )		->    tuple[tuple[int, int, int, int], tuple[int, int]]:


				'''simple docstring'''




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

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

				return public_key, private_key





def 	lowerCAmelCase_		(lowercase__						:       str     ,					lowercase__						:       int       )		->    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()

				lowerCAmelCase__			,		lowerCAmelCase__      			=						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 	lowerCAmelCase_		()		->    None:


				'''simple docstring'''




				print('''Making key files...'''       )
				make_key_files('''elgamal'''     ,					20_48       )
				print('''Key files generation successful'''       )


if __name__ == "__main__":
			main()













import pytest

import datasets


# Import fixture modules as plugins
_UpperCAmelCase			:		Tuple   				=    ["tests.fixtures.files", "tests.fixtures.hub", "tests.fixtures.fsspec"]





def 	lowerCAmelCase_		(lowercase__						:       Optional[int]     ,					lowercase__						:       int       )		->    Any:


				'''simple docstring'''




				for item in items:
								if any(marker in item.keywords for marker in ['''integration''', '''unit''']       ):
												continue
								item.add_marker(pytest.mark.unit       )





def 	lowerCAmelCase_		(lowercase__						:       str       )		->    List[str]:


				'''simple docstring'''




				config.addinivalue_line('''markers'''     ,					'''torchaudio_latest: mark test to run with torchaudio>=0.12'''       )





@pytest.fixture(autouse=lowercase__       )
def 	lowerCAmelCase_		(lowercase__						:       int     ,					lowercase__						:       Dict       )		->    Optional[Any]:


				'''simple docstring'''




				lowerCAmelCase__      			=						tmp_path_factory.getbasetemp() / '''cache'''
				lowerCAmelCase__      			=						test_hf_cache_home / '''datasets'''
				lowerCAmelCase__      			=						test_hf_cache_home / '''metrics'''
				lowerCAmelCase__      			=						test_hf_cache_home / '''modules'''
				monkeypatch.setattr('''datasets.config.HF_DATASETS_CACHE'''     ,					str(lowercase__       )       )
				monkeypatch.setattr('''datasets.config.HF_METRICS_CACHE'''     ,					str(lowercase__       )       )
				monkeypatch.setattr('''datasets.config.HF_MODULES_CACHE'''     ,					str(lowercase__       )       )
				lowerCAmelCase__      			=						test_hf_datasets_cache / '''downloads'''
				monkeypatch.setattr('''datasets.config.DOWNLOADED_DATASETS_PATH'''     ,					str(lowercase__       )       )
				lowerCAmelCase__      			=						test_hf_datasets_cache / '''downloads''' / '''extracted'''
				monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''     ,					str(lowercase__       )       )





@pytest.fixture(autouse=lowercase__     ,					scope='''session'''       )
def 	lowerCAmelCase_		()		->    int:


				'''simple docstring'''




				datasets.disable_progress_bar()





@pytest.fixture(autouse=lowercase__       )
def 	lowerCAmelCase_		(lowercase__						:       Dict       )		->    List[str]:


				'''simple docstring'''




				monkeypatch.setattr('''datasets.config.HF_UPDATE_DOWNLOAD_COUNTS'''     ,					lowercase__       )





@pytest.fixture
def 	lowerCAmelCase_		(lowercase__						:       List[str]       )		->    List[Any]:


				'''simple docstring'''




				monkeypatch.setattr('''sqlalchemy.util.deprecations.SILENCE_UBER_WARNING'''     ,					lowercase__       )





