



"""simple docstring"""

import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

a_			   =					3







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int			):



					"""simple docstring"""





					print("""Generating primitive root of p"""			)
					while True:
										snake_case_					:		Union[str, Any] 					=					random.randrange(3				,    SCREAMING_SNAKE_CASE__			)
										if pow(SCREAMING_SNAKE_CASE__				,    2				,    SCREAMING_SNAKE_CASE__			) == 1:
															continue
										if pow(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			) == 1:
															continue
										return g







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int			):



					"""simple docstring"""





					print("""Generating prime p..."""			)
					snake_case_					:		Dict 					=					rabin_miller.generate_large_prime(SCREAMING_SNAKE_CASE__			)  # select large prime number.
					snake_case_					:		Tuple 					=					primitive_root(SCREAMING_SNAKE_CASE__			)  # one primitive root on modulo p.
					snake_case_					:		Union[str, Any] 					=					random.randrange(3				,    SCREAMING_SNAKE_CASE__			)  # private_key -> have to be greater than 2 for safety.
					snake_case_					:		List[str] 					=					cryptomath.find_mod_inverse(pow(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)				,    SCREAMING_SNAKE_CASE__			)

					snake_case_					:		List[Any] 					=					(key_size, e_a, e_a, p)
					snake_case_					:		Any 					=					(key_size, d)

					return public_key, private_key







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  str				,    SCREAMING_SNAKE_CASE__ :  int			):



					"""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[int] 					=					generate_key(SCREAMING_SNAKE_CASE__			)
					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 							SCREAMING_SNAKE_CASE__      (		):



					"""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 copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


a_			   =					logging.get_logger(__name__)







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Optional[int]							       =		"""upernet"""







						def __init__(self   ,		lowercase__=None   ,		lowercase__=5_12   ,		lowercase__=0.02   ,		lowercase__=[1, 2, 3, 6]   ,		lowercase__=True   ,		lowercase__=0.4   ,		lowercase__=3_84   ,		lowercase__=2_56   ,		lowercase__=1   ,		lowercase__=False   ,		lowercase__=2_55   ,		**lowercase__   ,		):
											super().__init__(**lowercase__       )

											if backbone_config is None:
																logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""       )
																snake_case_					:		List[Any] 					=					CONFIG_MAPPING["""resnet"""](out_features=["""stage1""", """stage2""", """stage3""", """stage4"""]       )
											elif isinstance(lowercase__   ,		lowercase__       ):
																snake_case_					:		Tuple 					=					backbone_config.get("""model_type"""       )
																snake_case_					:		List[str] 					=					CONFIG_MAPPING[backbone_model_type]
																snake_case_					:		List[Any] 					=					config_class.from_dict(lowercase__       )

											snake_case_					:		List[Any] 					=					backbone_config
											snake_case_					:		Optional[Any] 					=					hidden_size
											snake_case_					:		Any 					=					initializer_range
											snake_case_					:		str 					=					pool_scales
											snake_case_					:		Dict 					=					use_auxiliary_head
											snake_case_					:		str 					=					auxiliary_loss_weight
											snake_case_					:		List[str] 					=					auxiliary_in_channels
											snake_case_					:		Optional[Any] 					=					auxiliary_channels
											snake_case_					:		Any 					=					auxiliary_num_convs
											snake_case_					:		List[Any] 					=					auxiliary_concat_input
											snake_case_					:		List[str] 					=					loss_ignore_index







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Dict 					=					copy.deepcopy(self.__dict__       )
											snake_case_					:		Union[str, Any] 					=					self.backbone_config.to_dict()
											snake_case_					:		Any 					=					self.__class__.model_type
											return output




