from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_      =      logging.get_logger(__name__)

A_      =      {
    "shi-labs/nat-mini-in1k-224": "https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json",
    # See all Nat models at https://huggingface.co/models?filter=nat
}






class      __lowercase					(    _A       ,     _A    ):
						lowercase					 =     'nat'

						lowercase					 =     {
						    'num_attention_heads': 'num_heads',
						    'num_hidden_layers': 'num_layers',
						}

						def __init__(	self				:      Union[str, Any]							,							__lowerCamelCase				:      List[Any]=4							,							__lowerCamelCase				:      int=3							,							__lowerCamelCase				:      Union[str, Any]=64							,							__lowerCamelCase				:      int=[3, 4, 6, 5]							,							__lowerCamelCase				:      Optional[int]=[2, 4, 8, 16]							,							__lowerCamelCase				:      Tuple=7							,							__lowerCamelCase				:      Tuple=3.0							,							__lowerCamelCase				:      int=True							,							__lowerCamelCase				:      int=0.0							,							__lowerCamelCase				:      Dict=0.0							,							__lowerCamelCase				:      List[str]=0.1							,							__lowerCamelCase				:      Union[str, Any]="gelu"							,							__lowerCamelCase				:      Dict=0.02							,							__lowerCamelCase				:      int=1E-5							,							__lowerCamelCase				:      str=0.0							,							__lowerCamelCase				:      List[Any]=None							,							__lowerCamelCase				:      List[str]=None							,							**__lowerCamelCase				:      Dict							,							)							->		Any:


									'''simple docstring'''

									super().__init__(**__lowerCamelCase   )

									lowercase							=		patch_size
									lowercase							=		num_channels
									lowercase							=		embed_dim
									lowercase							=		depths
									lowercase							=		len(__lowerCamelCase   )
									lowercase							=		num_heads
									lowercase							=		kernel_size
									lowercase							=		mlp_ratio
									lowercase							=		qkv_bias
									lowercase							=		hidden_dropout_prob
									lowercase							=		attention_probs_dropout_prob
									lowercase							=		drop_path_rate
									lowercase							=		hidden_act
									lowercase							=		layer_norm_eps
									lowercase							=		initializer_range
									# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
									# this indicates the channel dimension after the last stage of the model
									lowercase							=		int(embed_dim * 2 ** (len(__lowerCamelCase   ) - 1)   )
									lowercase							=		layer_scale_init_value
									lowercase							=		['''stem'''] + [f'stage{idx}' for idx in range(1							,							len(__lowerCamelCase   ) + 1   )]
									lowercase		,lowercase							=		get_aligned_output_features_output_indices(
									    out_features=__lowerCamelCase							,							out_indices=__lowerCamelCase							,							stage_names=self.stage_names   )






import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

A_      =      3






def        __UpperCAmelCase    (       UpperCAmelCase       )->       int:



			"""simple docstring"""







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






def        __UpperCAmelCase    (       UpperCAmelCase       )->       tuple[tuple[int, int, int, int], tuple[int, int]]:



			"""simple docstring"""







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

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

			return public_key, private_key






def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase       )->       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()

			lowercase		,lowercase							=		generate_key(UpperCAmelCase       )
			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    (       )->       None:



			"""simple docstring"""







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


if __name__ == "__main__":
						main()





