






'''simple docstring'''




import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    FlaubertForMultipleChoice,
		    FlaubertForQuestionAnswering,
		    FlaubertForQuestionAnsweringSimple,
		    FlaubertForSequenceClassification,
		    FlaubertForTokenClassification,
		    FlaubertModel,
		    FlaubertWithLMHeadModel,
		)
		from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST







class       __lowercase					(__lowerCamelCase    ):

	def __init__(      self   :						Optional[Any]  ,					UpperCAmelCase_   :						Optional[int]  ,					UpperCAmelCase_   :						Optional[int]=13  ,					UpperCAmelCase_   :						Optional[int]=7  ,					UpperCAmelCase_   :						Any=True  ,					UpperCAmelCase_   :						List[Any]=True  ,					UpperCAmelCase_   :						Tuple=True  ,					UpperCAmelCase_   :						Union[str, Any]=True  ,					UpperCAmelCase_   :						str=True  ,					UpperCAmelCase_   :						Optional[Any]=False  ,					UpperCAmelCase_   :						List[Any]=False  ,					UpperCAmelCase_   :						Optional[Any]=False  ,					UpperCAmelCase_   :						Optional[int]=2  ,					UpperCAmelCase_   :						int=99  ,					UpperCAmelCase_   :						List[str]=0  ,					UpperCAmelCase_   :						List[str]=32  ,					UpperCAmelCase_   :						int=5  ,					UpperCAmelCase_   :						Any=4  ,					UpperCAmelCase_   :						Dict=0.1  ,					UpperCAmelCase_   :						int=0.1  ,					UpperCAmelCase_   :						List[str]=512  ,					UpperCAmelCase_   :						Tuple=12  ,					UpperCAmelCase_   :						str=2  ,					UpperCAmelCase_   :						Tuple=0.02  ,					UpperCAmelCase_   :						Any=3  ,					UpperCAmelCase_   :						Optional[int]=4  ,					UpperCAmelCase_   :						Union[str, Any]="last"  ,					UpperCAmelCase_   :						Any=None  ,					UpperCAmelCase_   :						int=None  ,					):
			UpperCamelCase__				:					int					=					parent
			UpperCamelCase__				:					Any					=					batch_size
			UpperCamelCase__				:					Tuple					=					seq_length
			UpperCamelCase__				:					Tuple					=					is_training
			UpperCamelCase__				:					Union[str, Any]					=					use_input_lengths
			UpperCamelCase__				:					Any					=					use_token_type_ids
			UpperCamelCase__				:					List[Any]					=					use_labels
			UpperCamelCase__				:					Optional[Any]					=					gelu_activation
			UpperCamelCase__				:					Union[str, Any]					=					sinusoidal_embeddings
			UpperCamelCase__				:					Union[str, Any]					=					causal
			UpperCamelCase__				:					Optional[Any]					=					asm
			UpperCamelCase__				:					Union[str, Any]					=					n_langs
			UpperCamelCase__				:					str					=					vocab_size
			UpperCamelCase__				:					int					=					n_special
			UpperCamelCase__				:					Dict					=					hidden_size
			UpperCamelCase__				:					List[str]					=					num_hidden_layers
			UpperCamelCase__				:					Tuple					=					num_attention_heads
			UpperCamelCase__				:					str					=					hidden_dropout_prob
			UpperCamelCase__				:					Optional[int]					=					attention_probs_dropout_prob
			UpperCamelCase__				:					int					=					max_position_embeddings
			UpperCamelCase__				:					Optional[Any]					=					type_vocab_size
			UpperCamelCase__				:					Optional[Any]					=					type_sequence_label_size
			UpperCamelCase__				:					Dict					=					initializer_range
			UpperCamelCase__				:					int					=					num_labels
			UpperCamelCase__				:					Optional[Any]					=					num_choices
			UpperCamelCase__				:					Dict					=					summary_type
			UpperCamelCase__				:					int					=					use_proj
			UpperCamelCase__				:					Optional[int]					=					scope

	def      __UpperCamelCase							(      self   :						Dict):
			UpperCamelCase__				:					int					=					ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size)
			UpperCamelCase__				:					List[str]					=					random_attention_mask([self.batch_size, self.seq_length])

			UpperCamelCase__				:					Any					=					None
			if self.use_input_lengths:
					UpperCamelCase__				:					Union[str, Any]					=					(
					    ids_tensor([self.batch_size]  ,					vocab_size=2) + self.seq_length - 2
					)  # small variation of seq_length

			UpperCamelCase__				:					Optional[int]					=					None
			if self.use_token_type_ids:
					UpperCamelCase__				:					Optional[int]					=					ids_tensor([self.batch_size, self.seq_length]  ,					self.n_langs)

			UpperCamelCase__				:					str					=					None
			UpperCamelCase__				:					List[str]					=					None
			UpperCamelCase__				:					int					=					None
			if self.use_labels:
					UpperCamelCase__				:					str					=					ids_tensor([self.batch_size]  ,					self.type_sequence_label_size)
					UpperCamelCase__				:					List[str]					=					ids_tensor([self.batch_size, self.seq_length]  ,					self.num_labels)
					UpperCamelCase__				:					List[str]					=					ids_tensor([self.batch_size]  ,					2).float()
					UpperCamelCase__				:					str					=					ids_tensor([self.batch_size]  ,					self.num_choices)

			UpperCamelCase__				:					Tuple					=					self.get_config()

			return (
			    config,
			    input_ids,
			    token_type_ids,
			    input_lengths,
			    sequence_labels,
			    token_labels,
			    is_impossible_labels,
			    choice_labels,
			    input_mask,
			)

	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			return FlaubertConfig(
			    vocab_size=self.vocab_size  ,					n_special=self.n_special  ,					emb_dim=self.hidden_size  ,					n_layers=self.num_hidden_layers  ,					n_heads=self.num_attention_heads  ,					dropout=self.hidden_dropout_prob  ,					attention_dropout=self.attention_probs_dropout_prob  ,					gelu_activation=self.gelu_activation  ,					sinusoidal_embeddings=self.sinusoidal_embeddings  ,					asm=self.asm  ,					causal=self.causal  ,					n_langs=self.n_langs  ,					max_position_embeddings=self.max_position_embeddings  ,					initializer_range=self.initializer_range  ,					summary_type=self.summary_type  ,					use_proj=self.use_proj  ,					)

	def      __UpperCamelCase							(      self   :						Any  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						List[Any]  ,					UpperCAmelCase_   :						Any  ,					):
			UpperCamelCase__				:					str					=					FlaubertModel(config=UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()
			UpperCamelCase__				:					Union[str, Any]					=					model(UpperCAmelCase_  ,					lengths=UpperCAmelCase_  ,					langs=UpperCAmelCase_)
			UpperCamelCase__				:					Optional[Any]					=					model(UpperCAmelCase_  ,					langs=UpperCAmelCase_)
			UpperCamelCase__				:					Any					=					model(UpperCAmelCase_)
			self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.hidden_size))

	def      __UpperCamelCase							(      self   :						str  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						Optional[int]  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						List[Any]  ,					UpperCAmelCase_   :						Any  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						Dict  ,					):
			UpperCamelCase__				:					List[Any]					=					FlaubertWithLMHeadModel(UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()

			UpperCamelCase__				:					Optional[int]					=					model(UpperCAmelCase_  ,					token_type_ids=UpperCAmelCase_  ,					labels=UpperCAmelCase_)
			self.parent.assertEqual(result.loss.shape  ,					())
			self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.seq_length, self.vocab_size))

	def      __UpperCamelCase							(      self   :						List[str]  ,					UpperCAmelCase_   :						List[Any]  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						List[Any]  ,					UpperCAmelCase_   :						Any  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						Optional[int]  ,					):
			UpperCamelCase__				:					List[Any]					=					FlaubertForQuestionAnsweringSimple(UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()

			UpperCamelCase__				:					List[Any]					=					model(UpperCAmelCase_)

			UpperCamelCase__				:					List[str]					=					model(UpperCAmelCase_  ,					start_positions=UpperCAmelCase_  ,					end_positions=UpperCAmelCase_)
			self.parent.assertEqual(result.start_logits.shape  ,					(self.batch_size, self.seq_length))
			self.parent.assertEqual(result.end_logits.shape  ,					(self.batch_size, self.seq_length))

	def      __UpperCamelCase							(      self   :						int  ,					UpperCAmelCase_   :						Optional[Any]  ,					UpperCAmelCase_   :						Union[str, Any]  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						Optional[Any]  ,					UpperCAmelCase_   :						Any  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						Union[str, Any]  ,					UpperCAmelCase_   :						List[str]  ,					):
			UpperCamelCase__				:					str					=					FlaubertForQuestionAnswering(UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()

			UpperCamelCase__				:					Optional[int]					=					model(UpperCAmelCase_)

			UpperCamelCase__				:					Optional[Any]					=					model(
			    UpperCAmelCase_  ,					start_positions=UpperCAmelCase_  ,					end_positions=UpperCAmelCase_  ,					cls_index=UpperCAmelCase_  ,					is_impossible=UpperCAmelCase_  ,					p_mask=UpperCAmelCase_  ,					)

			UpperCamelCase__				:					Optional[int]					=					model(
			    UpperCAmelCase_  ,					start_positions=UpperCAmelCase_  ,					end_positions=UpperCAmelCase_  ,					cls_index=UpperCAmelCase_  ,					is_impossible=UpperCAmelCase_  ,					)

			(UpperCamelCase__	)				:					Tuple					=					result_with_labels.to_tuple()

			UpperCamelCase__				:					int					=					model(UpperCAmelCase_  ,					start_positions=UpperCAmelCase_  ,					end_positions=UpperCAmelCase_)

			(UpperCamelCase__	)				:					int					=					result_with_labels.to_tuple()

			self.parent.assertEqual(result_with_labels.loss.shape  ,					())
			self.parent.assertEqual(result.start_top_log_probs.shape  ,					(self.batch_size, model.config.start_n_top))
			self.parent.assertEqual(result.start_top_index.shape  ,					(self.batch_size, model.config.start_n_top))
			self.parent.assertEqual(
			    result.end_top_log_probs.shape  ,					(self.batch_size, model.config.start_n_top * model.config.end_n_top))
			self.parent.assertEqual(
			    result.end_top_index.shape  ,					(self.batch_size, model.config.start_n_top * model.config.end_n_top))
			self.parent.assertEqual(result.cls_logits.shape  ,					(self.batch_size,))

	def      __UpperCamelCase							(      self   :						Optional[int]  ,					UpperCAmelCase_   :						Optional[int]  ,					UpperCAmelCase_   :						Optional[int]  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						Optional[int]  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						int  ,					):
			UpperCamelCase__				:					str					=					FlaubertForSequenceClassification(UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()

			UpperCamelCase__				:					Tuple					=					model(UpperCAmelCase_)
			UpperCamelCase__				:					Any					=					model(UpperCAmelCase_  ,					labels=UpperCAmelCase_)

			self.parent.assertEqual(result.loss.shape  ,					())
			self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.type_sequence_label_size))

	def      __UpperCamelCase							(      self   :						Optional[int]  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						int  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						List[Any]  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						Optional[Any]  ,					):
			UpperCamelCase__				:					List[Any]					=					self.num_labels
			UpperCamelCase__				:					Optional[Any]					=					FlaubertForTokenClassification(UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()

			UpperCamelCase__				:					Union[str, Any]					=					model(UpperCAmelCase_  ,					attention_mask=UpperCAmelCase_  ,					labels=UpperCAmelCase_)
			self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.seq_length, self.num_labels))

	def      __UpperCamelCase							(      self   :						Tuple  ,					UpperCAmelCase_   :						Optional[Any]  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						Any  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						Union[str, Any]  ,					UpperCAmelCase_   :						Dict  ,					UpperCAmelCase_   :						List[Any]  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						int  ,					):
			UpperCamelCase__				:					Optional[Any]					=					self.num_choices
			UpperCamelCase__				:					List[Any]					=					FlaubertForMultipleChoice(config=UpperCAmelCase_)
			model.to(UpperCAmelCase_)
			model.eval()
			UpperCamelCase__				:					List[str]					=					input_ids.unsqueeze(1).expand(-1  ,					self.num_choices  ,					-1).contiguous()
			UpperCamelCase__				:					List[str]					=					token_type_ids.unsqueeze(1).expand(-1  ,					self.num_choices  ,					-1).contiguous()
			UpperCamelCase__				:					Tuple					=					input_mask.unsqueeze(1).expand(-1  ,					self.num_choices  ,					-1).contiguous()
			UpperCamelCase__				:					List[str]					=					model(
			    UpperCAmelCase_  ,					attention_mask=UpperCAmelCase_  ,					token_type_ids=UpperCAmelCase_  ,					labels=UpperCAmelCase_  ,					)
			self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.num_choices))





	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			UpperCamelCase__				:					List[Any]					=					self.prepare_config_and_inputs()
			(
			    UpperCamelCase__	
			)				:					str					=					config_and_inputs
			UpperCamelCase__				:					Optional[Any]					=					{
			    'input_ids': input_ids,
			    'token_type_ids': token_type_ids,
			    'lengths': input_lengths,
			    'attention_mask': input_mask,
			}
			return config, inputs_dict







@require_torch
class       __lowercase					(__lowerCamelCase   ,				__lowerCamelCase   ,				unittest.TestCase    ):
	_lowerCamelCase              =  (
	    (
	        FlaubertModel,
	        FlaubertWithLMHeadModel,
	        FlaubertForQuestionAnswering,
	        FlaubertForQuestionAnsweringSimple,
	        FlaubertForSequenceClassification,
	        FlaubertForTokenClassification,
	        FlaubertForMultipleChoice,
	    )
	    if is_torch_available()
	    else ()
	)
	_lowerCamelCase              =  (
	    {
	        '''feature-extraction''': FlaubertModel,
	        '''fill-mask''': FlaubertWithLMHeadModel,
	        '''question-answering''': FlaubertForQuestionAnsweringSimple,
	        '''text-classification''': FlaubertForSequenceClassification,
	        '''token-classification''': FlaubertForTokenClassification,
	        '''zero-shot''': FlaubertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	def      __UpperCamelCase							(      self   :						Tuple  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						Any  ,					UpperCAmelCase_   :						Optional[int]  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						Union[str, Any]):
			if (
			    pipeline_test_casse_name == "QAPipelineTests"
			    and tokenizer_name is not None
			    and not tokenizer_name.endswith('Fast')
			):
					# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
					# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
					# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
					return True

			return False

	def      __UpperCamelCase							(      self   :						Optional[Any]  ,					UpperCAmelCase_   :						Optional[Any]  ,					UpperCAmelCase_   :						Optional[Any]  ,					UpperCAmelCase_   :						Union[str, Any]=False):
			UpperCamelCase__				:					str					=					super()._prepare_for_class(UpperCAmelCase_  ,					UpperCAmelCase_  ,					return_labels=UpperCAmelCase_)

			if return_labels:
					if model_class.__name__ == "FlaubertForQuestionAnswering":
							UpperCamelCase__				:					int					=					torch.zeros(
							    self.model_tester.batch_size  ,					dtype=torch.long  ,					device=UpperCAmelCase_)
							UpperCamelCase__				:					Union[str, Any]					=					torch.zeros(
							    self.model_tester.batch_size  ,					dtype=torch.long  ,					device=UpperCAmelCase_)

			return inputs_dict

	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			UpperCamelCase__				:					str					=					FlaubertModelTester(self)
			UpperCamelCase__				:					int					=					ConfigTester(self  ,					config_class=UpperCAmelCase_  ,					emb_dim=37)

	def      __UpperCamelCase							(      self   :						Optional[Any]):
			self.config_tester.run_common_tests()

	def      __UpperCamelCase							(      self   :						str):
			UpperCamelCase__				:					str					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_model(*UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Any):
			UpperCamelCase__				:					Union[str, Any]					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_lm_head(*UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Optional[int]):
			UpperCamelCase__				:					Dict					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_simple_qa(*UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Optional[int]):
			UpperCamelCase__				:					int					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_qa(*UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Optional[Any]):
			UpperCamelCase__				:					Tuple					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_sequence_classif(*UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			UpperCamelCase__				:					Dict					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_token_classif(*UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Optional[int]):
			UpperCamelCase__				:					Dict					=					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_multiple_choice(*UpperCAmelCase_)

	@slow
	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					UpperCamelCase__				:					int					=					FlaubertModel.from_pretrained(UpperCAmelCase_)
					self.assertIsNotNone(UpperCAmelCase_)





	@slow
	@require_torch_gpu
	def      __UpperCamelCase							(      self   :						Optional[int]):
			UpperCamelCase__				:					List[Any]					=					self.model_tester.prepare_config_and_inputs_for_common()
			for model_class in self.all_model_classes:
					# FlauBertForMultipleChoice behaves incorrectly in JIT environments.
					if model_class == FlaubertForMultipleChoice:
							return

					UpperCamelCase__				:					str					=					True
					UpperCamelCase__				:					List[Any]					=					model_class(config=UpperCAmelCase_)

					UpperCamelCase__				:					Tuple					=					self._prepare_for_class(UpperCAmelCase_  ,					UpperCAmelCase_)
					UpperCamelCase__				:					Optional[int]					=					torch.jit.trace(
					    UpperCAmelCase_  ,					(inputs_dict['input_ids'].to('cpu'), inputs_dict['attention_mask'].to('cpu')))

					with tempfile.TemporaryDirectory() as tmp:
							torch.jit.save(UpperCAmelCase_  ,					os.path.join(UpperCAmelCase_  ,					'traced_model.pt'))
							UpperCamelCase__				:					List[str]					=					torch.jit.load(os.path.join(UpperCAmelCase_  ,					'traced_model.pt')  ,					map_location=UpperCAmelCase_)
							loaded(inputs_dict['input_ids'].to(UpperCAmelCase_)  ,					inputs_dict['attention_mask'].to(UpperCAmelCase_))







@require_torch
class       __lowercase					(unittest.TestCase    ):

	@slow
	def      __UpperCamelCase							(      self   :						List[Any]):
			UpperCamelCase__				:					str					=					FlaubertModel.from_pretrained('flaubert/flaubert_base_cased')
			UpperCamelCase__				:					Dict					=					torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]])
			with torch.no_grad():
					UpperCamelCase__				:					str					=					model(UpperCAmelCase_)[0]
			UpperCamelCase__				:					Optional[int]					=					torch.Size((1, 11, 768))
			self.assertEqual(output.shape  ,					UpperCAmelCase_)
			UpperCamelCase__				:					Optional[Any]					=					torch.tensor(
			    [[[-2.62_51, -1.42_98, -0.02_27], [-2.85_10, -1.63_87, 0.22_58], [-2.81_14, -1.18_32, -0.30_66]]])

			self.assertTrue(torch.allclose(output[:, :3, :3]  ,					UpperCAmelCase_  ,					atol=1e-4))












'''simple docstring'''




import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

lowerCAmelCase__          =						3







def       __UpperCAmelCase						(  lowerCamelCase_)							->     int:
		print('Generating primitive root of p')
		while True:
				UpperCamelCase__				:					Any					=					random.randrange(3     ,      lowerCamelCase_)
				if pow(lowerCamelCase_     ,      2     ,      lowerCamelCase_) == 1:
						continue
				if pow(lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_) == 1:
						continue
				return g







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

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

		return public_key, private_key







def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_)							->     None:
		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()

		UpperCamelCase__,	UpperCamelCase__				:					Union[str, Any]					=					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       __UpperCAmelCase						(  )							->     None:
		print('Making key files...')
		make_key_files('elgamal'     ,      2_048)
		print('Key files generation successful')


if __name__ == "__main__":
		main()




