





'''simple docstring'''



import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

	if is_vision_available():
		from transformers import MaskFormerImageProcessor

if is_vision_available():
	from PIL import Image






class 							__lowercase    :







	'''simple docstring'''

	def __init__(self       ,_lowerCamelCase       ,_lowerCamelCase=2       ,_lowerCamelCase=True       ,_lowerCamelCase=False       ,_lowerCamelCase=10       ,_lowerCamelCase=3       ,_lowerCamelCase=32 * 4       ,_lowerCamelCase=32 * 6       ,_lowerCamelCase=4       ,_lowerCamelCase=32       ,)							->							Optional[Any]:







				'''simple docstring'''





				__lowercase			  =							parent
				__lowercase			  =							batch_size
				__lowercase			  =							is_training
				__lowercase			  =							use_auxiliary_loss
				__lowercase			  =							num_queries
				__lowercase			  =							num_channels
				__lowercase			  =							min_size
				__lowercase			  =							max_size
				__lowercase			  =							num_labels
				__lowercase			  =							mask_feature_size


	def   _UpperCAmelCase       (self	)							->							Dict:







				'''simple docstring'''





				__lowercase			  =							floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]	).to(
				    _lowerCamelCase	)

				__lowercase			  =							torch.ones([self.batch_size, self.min_size, self.max_size]       ,device=_lowerCamelCase	)

				__lowercase			  =							(
				    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]       ,device=_lowerCamelCase	) > 0.5
				).float()
				__lowercase			  =							(torch.rand((self.batch_size, self.num_labels)       ,device=_lowerCamelCase	) > 0.5).long()

				__lowercase			  =							self.get_config()
				return config, pixel_values, pixel_mask, mask_labels, class_labels


	def   _UpperCAmelCase       (self	)							->							Optional[Any]:







				'''simple docstring'''





				return MaskFormerConfig.from_backbone_and_decoder_configs(
				    backbone_config=SwinConfig(
				        depths=[1, 1, 1, 1]       ,)       ,decoder_config=DetrConfig(
				        decoder_ffn_dim=128       ,num_queries=self.num_queries       ,decoder_attention_heads=2       ,d_model=self.mask_feature_size       ,)       ,mask_feature_size=self.mask_feature_size       ,fpn_feature_size=self.mask_feature_size       ,num_channels=self.num_channels       ,num_labels=self.num_labels       ,)


	def   _UpperCAmelCase       (self	)							->							str:







				'''simple docstring'''





				__lowercase  ,						__lowercase  ,						__lowercase  ,						__lowercase  ,						__lowercase			  =							self.prepare_config_and_inputs()
				__lowercase			  =							{'''pixel_values''': pixel_values, '''pixel_mask''': pixel_mask}
				return config, inputs_dict


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase	)							->							Optional[int]:







				'''simple docstring'''





				__lowercase			  =							output.encoder_hidden_states
				__lowercase			  =							output.pixel_decoder_hidden_states
				__lowercase			  =							output.transformer_decoder_hidden_states

				self.parent.assertTrue(len(_lowerCamelCase	)       ,len(config.backbone_config.depths	)	)
				self.parent.assertTrue(len(_lowerCamelCase	)       ,len(config.backbone_config.depths	)	)
				self.parent.assertTrue(len(_lowerCamelCase	)       ,config.decoder_config.decoder_layers	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase=False	)							->							int:







				'''simple docstring'''





				with torch.no_grad():
							__lowercase			  =							MaskFormerModel(config=_lowerCamelCase	)
							model.to(_lowerCamelCase	)
							model.eval()

							__lowercase			  =							model(pixel_values=_lowerCamelCase       ,pixel_mask=_lowerCamelCase	)
							__lowercase			  =							model(_lowerCamelCase       ,output_hidden_states=_lowerCamelCase	)
				# the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
				# encoder and pixel decoder
				self.parent.assertEqual(
				    output.transformer_decoder_last_hidden_state.shape       ,(self.batch_size, self.num_queries, self.mask_feature_size)       ,)
				# let's ensure the other two hidden state exists
				self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None	)
				self.parent.assertTrue(output.encoder_last_hidden_state is not None	)

				if output_hidden_states:
							self.check_output_hidden_state(_lowerCamelCase       ,_lowerCamelCase	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase	)							->							str:







				'''simple docstring'''





				__lowercase			  =							MaskFormerForInstanceSegmentation(config=_lowerCamelCase	)
				model.to(_lowerCamelCase	)
				model.eval()

				def comm_check_on_output(_lowerCamelCase	):
							# let's still check that all the required stuff is there
							self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None	)
							self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None	)
							self.parent.assertTrue(result.encoder_last_hidden_state is not None	)
							# okay, now we need to check the logits shape
							# due to the encoder compression, masks have a //4 spatial size
							self.parent.assertEqual(
							    result.masks_queries_logits.shape       ,(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)       ,)
							# + 1 for null class
							self.parent.assertEqual(
							    result.class_queries_logits.shape       ,(self.batch_size, self.num_queries, self.num_labels + 1)	)

				with torch.no_grad():
							__lowercase			  =							model(pixel_values=_lowerCamelCase       ,pixel_mask=_lowerCamelCase	)
							__lowercase			  =							model(_lowerCamelCase	)

							comm_check_on_output(_lowerCamelCase	)

							__lowercase			  =							model(
							    pixel_values=_lowerCamelCase       ,pixel_mask=_lowerCamelCase       ,mask_labels=_lowerCamelCase       ,class_labels=_lowerCamelCase	)

				comm_check_on_output(_lowerCamelCase	)

				self.parent.assertTrue(result.loss is not None	)
				self.parent.assertEqual(result.loss.shape       ,torch.Size([1]	)	)






@require_torch
class 							__lowercase    ( lowerCAmelCase__	, lowerCAmelCase__	, unittest.TestCase  ):







	'''simple docstring'''

	a      :			Optional[Any]     =    (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
	a      :			Optional[int]     =    (
	    {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
	    if is_torch_available()
	    else {}
	)

	a      :			Tuple     =    False
	a      :			str     =    False
	a      :			int     =    False
	a      :			Dict     =    False


	def   _UpperCAmelCase       (self	)							->							Tuple:







				'''simple docstring'''





				__lowercase			  =							MaskFormerModelTester(self	)
				__lowercase			  =							ConfigTester(self       ,config_class=_lowerCamelCase       ,has_text_modality=_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				self.config_tester.run_common_tests()


	def   _UpperCAmelCase       (self	)							->							Optional[int]:







				'''simple docstring'''





				__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs_for_common()
				self.model_tester.create_and_check_maskformer_model(_lowerCamelCase       ,**_lowerCamelCase       ,output_hidden_states=_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							List[str]:







				'''simple docstring'''





				__lowercase			  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_lowerCamelCase	)


	@unittest.skip(reason='''MaskFormer does not use inputs_embeds'''	)
	def   _UpperCAmelCase       (self	)							->							Tuple:







				'''simple docstring'''





				pass


	@unittest.skip(reason='''MaskFormer does not have a get_input_embeddings method'''	)
	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				pass


	@unittest.skip(reason='''MaskFormer is not a generative model'''	)
	def   _UpperCAmelCase       (self	)							->							Dict:







				'''simple docstring'''





				pass


	@unittest.skip(reason='''MaskFormer does not use token embeddings'''	)
	def   _UpperCAmelCase       (self	)							->							int:







				'''simple docstring'''





				pass


	@require_torch_multi_gpu
	@unittest.skip(
	    reason='''MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''	)
	def   _UpperCAmelCase       (self	)							->							Optional[Any]:







				'''simple docstring'''





				pass


	@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''	)
	def   _UpperCAmelCase       (self	)							->							List[Any]:







				'''simple docstring'''





				pass


	def   _UpperCAmelCase       (self	)							->							Optional[int]:







				'''simple docstring'''





				__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							__lowercase			  =							model_class(_lowerCamelCase	)
							__lowercase			  =							inspect.signature(model.forward	)
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							__lowercase			  =							[*signature.parameters.keys()]

							__lowercase			  =							['''pixel_values''']
							self.assertListEqual(arg_names[:1]       ,_lowerCamelCase	)


	@slow
	def   _UpperCAmelCase       (self	)							->							Optional[int]:







				'''simple docstring'''





				for model_name in ["facebook/maskformer-swin-small-coco"]:
							__lowercase			  =							MaskFormerModel.from_pretrained(_lowerCamelCase	)
							self.assertIsNotNone(_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							Dict:







				'''simple docstring'''





				__lowercase			  =							(self.model_tester.min_size,) * 2
				__lowercase			  =							{
				    '''pixel_values''': torch.randn((2, 3, *size)       ,device=_lowerCamelCase	),
				    '''mask_labels''': torch.randn((2, 10, *size)       ,device=_lowerCamelCase	),
				    '''class_labels''': torch.zeros(2       ,10       ,device=_lowerCamelCase	).long(),
				}

				__lowercase			  =							MaskFormerForInstanceSegmentation(MaskFormerConfig()	).to(_lowerCamelCase	)
				__lowercase			  =							model(**_lowerCamelCase	)
				self.assertTrue(outputs.loss is not None	)


	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs_for_common()
				self.model_tester.create_and_check_maskformer_model(_lowerCamelCase       ,**_lowerCamelCase       ,output_hidden_states=_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							List[Any]:







				'''simple docstring'''





				__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							__lowercase			  =							model_class(_lowerCamelCase	).to(_lowerCamelCase	)
							__lowercase			  =							model(**_lowerCamelCase       ,output_attentions=_lowerCamelCase	)
							self.assertTrue(outputs.attentions is not None	)


	def   _UpperCAmelCase       (self	)							->							Tuple:







				'''simple docstring'''





				if not self.model_tester.is_training:
							return
				# only MaskFormerForInstanceSegmentation has the loss
				__lowercase			  =							self.all_model_classes[1]
				__lowercase  ,						__lowercase  ,						__lowercase  ,						__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs()

				__lowercase			  =							model_class(_lowerCamelCase	)
				model.to(_lowerCamelCase	)
				model.train()

				__lowercase			  =							model(_lowerCamelCase       ,mask_labels=_lowerCamelCase       ,class_labels=_lowerCamelCase	).loss
				loss.backward()


	def   _UpperCAmelCase       (self	)							->							List[Any]:







				'''simple docstring'''





				__lowercase			  =							self.all_model_classes[1]
				__lowercase  ,						__lowercase  ,						__lowercase  ,						__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs()
				__lowercase			  =							True
				__lowercase			  =							True

				__lowercase			  =							model_class(_lowerCamelCase	)
				model.to(_lowerCamelCase	)
				model.train()

				__lowercase			  =							model(_lowerCamelCase       ,mask_labels=_lowerCamelCase       ,class_labels=_lowerCamelCase	)

				__lowercase			  =							outputs.encoder_hidden_states[0]
				encoder_hidden_states.retain_grad()

				__lowercase			  =							outputs.pixel_decoder_hidden_states[0]
				pixel_decoder_hidden_states.retain_grad()
				# we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
				__lowercase			  =							outputs.transformer_decoder_hidden_states[0]
				transformer_decoder_hidden_states.retain_grad()

				__lowercase			  =							outputs.attentions[0]
				attentions.retain_grad()

				outputs.loss.backward(retain_graph=_lowerCamelCase	)

				self.assertIsNotNone(encoder_hidden_states.grad	)
				self.assertIsNotNone(pixel_decoder_hidden_states.grad	)
				self.assertIsNotNone(transformer_decoder_hidden_states.grad	)
				self.assertIsNotNone(attentions.grad	)





_SCREAMING_SNAKE_CASE   =      1e-4




def 				_lowerCAmelCase  (			):
			__lowercase			  =							Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
			return image






@require_vision
@slow
class 							__lowercase    ( unittest.TestCase  ):







	'''simple docstring'''

	@cached_property
	def   _UpperCAmelCase       (self	)							->							str:







				'''simple docstring'''





				return (
				    MaskFormerImageProcessor.from_pretrained('''facebook/maskformer-swin-small-coco'''	)
				    if is_vision_available()
				    else None
				)


	def   _UpperCAmelCase       (self	)							->							Any:







				'''simple docstring'''





				__lowercase			  =							MaskFormerModel.from_pretrained('''facebook/maskformer-swin-small-coco'''	).to(_lowerCamelCase	)
				__lowercase			  =							self.default_image_processor
				__lowercase			  =							prepare_img()
				__lowercase			  =							image_processor(_lowerCamelCase       ,return_tensors='''pt'''	).to(_lowerCamelCase	)
				__lowercase			  =							inputs['''pixel_values'''].shape
				# check size is divisible by 32
				self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0	)
				# check size
				self.assertEqual(_lowerCamelCase       ,(1, 3, 800, 1088)	)

				with torch.no_grad():
							__lowercase			  =							model(**_lowerCamelCase	)

				__lowercase			  =							torch.tensor(
				    [[-0.0_4_8_2, 0.9_2_2_8, 0.4_9_5_1], [-0.2_5_4_7, 0.8_0_1_7, 0.8_5_2_7], [-0.0_0_6_9, 0.3_3_8_5, -0.0_0_8_9]]	).to(_lowerCamelCase	)
				self.assertTrue(
				    torch.allclose(
				        outputs.encoder_last_hidden_state[0, 0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)

				__lowercase			  =							torch.tensor(
				    [[-0.8_4_2_2, -0.8_4_3_4, -0.9_7_1_8], [-1.0_1_4_4, -0.5_5_6_5, -0.4_1_9_5], [-1.0_0_3_8, -0.4_4_8_4, -0.1_9_6_1]]	).to(_lowerCamelCase	)
				self.assertTrue(
				    torch.allclose(
				        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)

				__lowercase			  =							torch.tensor(
				    [[0.2_8_5_2, -0.0_1_5_9, 0.9_7_3_5], [0.6_2_5_4, 0.1_8_5_8, 0.8_5_2_9], [-0.0_6_8_0, -0.4_1_1_6, 1.8_4_1_3]]	).to(_lowerCamelCase	)
				self.assertTrue(
				    torch.allclose(
				        outputs.transformer_decoder_last_hidden_state[0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)


	def   _UpperCAmelCase       (self	)							->							Optional[int]:







				'''simple docstring'''





				__lowercase			  =							(
				    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''	)
				    .to(_lowerCamelCase	)
				    .eval()
				)
				__lowercase			  =							self.default_image_processor
				__lowercase			  =							prepare_img()
				__lowercase			  =							image_processor(_lowerCamelCase       ,return_tensors='''pt'''	).to(_lowerCamelCase	)
				__lowercase			  =							inputs['''pixel_values'''].shape
				# check size is divisible by 32
				self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0	)
				# check size
				self.assertEqual(_lowerCamelCase       ,(1, 3, 800, 1088)	)

				with torch.no_grad():
							__lowercase			  =							model(**_lowerCamelCase	)
				# masks_queries_logits
				__lowercase			  =							outputs.masks_queries_logits
				self.assertEqual(
				    masks_queries_logits.shape       ,(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)       ,)
				__lowercase			  =							[
				    [-1.3_7_3_7_1_2_4, -1.7_7_2_4_9_3_7, -1.9_3_6_4_2_3_3],
				    [-1.5_9_7_7_2_8_1, -1.9_8_6_7_9_3_9, -2.1_5_2_3_6_9_5],
				    [-1.5_7_9_5_3_9_8, -1.9_2_6_9_8_3_2, -2.0_9_3_9_4_2],
				]
				__lowercase			  =							torch.tensor(_lowerCamelCase	).to(_lowerCamelCase	)
				self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)
				# class_queries_logits
				__lowercase			  =							outputs.class_queries_logits
				self.assertEqual(
				    class_queries_logits.shape       ,(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)	)
				__lowercase			  =							torch.tensor(
				    [
				        [1.6_5_1_2E0_0, -5.2_5_7_2E0_0, -3.3_5_1_9E0_0],
				        [3.6_1_6_9E-0_2, -5.9_0_2_5E0_0, -2.9_3_1_3E0_0],
				        [1.0_7_6_6E-0_4, -7.7_6_3_0E0_0, -5.1_2_6_3E0_0],
				    ]	).to(_lowerCamelCase	)
				self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)


	def   _UpperCAmelCase       (self	)							->							Tuple:







				'''simple docstring'''





				__lowercase			  =							(
				    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-resnet101-coco-stuff'''	)
				    .to(_lowerCamelCase	)
				    .eval()
				)
				__lowercase			  =							self.default_image_processor
				__lowercase			  =							prepare_img()
				__lowercase			  =							image_processor(_lowerCamelCase       ,return_tensors='''pt'''	).to(_lowerCamelCase	)
				__lowercase			  =							inputs['''pixel_values'''].shape
				# check size is divisible by 32
				self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0	)
				# check size
				self.assertEqual(_lowerCamelCase       ,(1, 3, 800, 1088)	)

				with torch.no_grad():
							__lowercase			  =							model(**_lowerCamelCase	)
				# masks_queries_logits
				__lowercase			  =							outputs.masks_queries_logits
				self.assertEqual(
				    masks_queries_logits.shape       ,(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)       ,)
				__lowercase			  =							[[-0.9_0_4_6, -2.6_3_6_6, -4.6_0_6_2], [-3.4_1_7_9, -5.7_8_9_0, -8.8_0_5_7], [-4.9_1_7_9, -7.6_5_6_0, -1_0.7_7_1_1]]
				__lowercase			  =							torch.tensor(_lowerCamelCase	).to(_lowerCamelCase	)
				self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)
				# class_queries_logits
				__lowercase			  =							outputs.class_queries_logits
				self.assertEqual(
				    class_queries_logits.shape       ,(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)	)
				__lowercase			  =							torch.tensor(
				    [[4.7_1_8_8, -3.2_5_8_5, -2.8_8_5_7], [6.6_8_7_1, -2.9_1_8_1, -1.2_4_8_7], [7.2_4_4_9, -2.2_7_6_4, -2.1_8_7_4]]	).to(_lowerCamelCase	)
				self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]       ,_lowerCamelCase       ,atol=_lowerCamelCase	)	)


	def   _UpperCAmelCase       (self	)							->							List[Any]:







				'''simple docstring'''





				__lowercase			  =							(
				    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''	)
				    .to(_lowerCamelCase	)
				    .eval()
				)
				__lowercase			  =							self.default_image_processor

				__lowercase			  =							image_processor(
				    [np.zeros((3, 800, 1333)	), np.zeros((3, 800, 1333)	)]       ,segmentation_maps=[np.zeros((384, 384)	).astype(np.floataa	), np.zeros((384, 384)	).astype(np.floataa	)]       ,return_tensors='''pt'''       ,)

				__lowercase			  =							inputs['''pixel_values'''].to(_lowerCamelCase	)
				__lowercase			  =							[el.to(_lowerCamelCase	) for el in inputs['''mask_labels''']]
				__lowercase			  =							[el.to(_lowerCamelCase	) for el in inputs['''class_labels''']]

				with torch.no_grad():
							__lowercase			  =							model(**_lowerCamelCase	)

				self.assertTrue(outputs.loss is not None	)












'''simple docstring'''



import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812




def 				_lowerCAmelCase  (			):
			print('''Making key files...'''			)
			make_key_files('''rsa'''						,    1_0_2_4			)
			print('''Key files generation successful.'''			)




def 				_lowerCAmelCase  (			lowerCamelCase_     :					int			):
			print('''Generating prime p...'''			)
			__lowercase			  =							rabinMiller.generate_large_prime(lowerCamelCase_			)
			print('''Generating prime q...'''			)
			__lowercase			  =							rabinMiller.generate_large_prime(lowerCamelCase_			)
			__lowercase			  =							p * q

			print('''Generating e that is relatively prime to (p - 1) * (q - 1)...'''			)
			while True:
						__lowercase			  =							random.randrange(2 ** (key_size - 1)						,    2 ** (key_size)			)
						if cryptoMath.gcd(lowerCamelCase_						,    (p - 1) * (q - 1)			) == 1:
									break

			print('''Calculating d that is mod inverse of e...'''			)
			__lowercase			  =							cryptoMath.find_mod_inverse(lowerCamelCase_						,    (p - 1) * (q - 1)			)

			__lowercase			  =							(n, e)
			__lowercase			  =							(n, d)
			return (public_key, private_key)




def 				_lowerCAmelCase  (			lowerCamelCase_     :					str						,    lowerCamelCase_     :					int			):
			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(lowerCamelCase_			)
			print(f"\nWriting public key to file {name}_pubkey.txt..."			)
			with open(f"{name}_pubkey.txt"						,    '''w'''			) as out_file:
						out_file.write(f"{key_size},{public_key[0]},{public_key[1]}"			)

			print(f"Writing private key to file {name}_privkey.txt..."			)
			with open(f"{name}_privkey.txt"						,    '''w'''			) as out_file:
						out_file.write(f"{key_size},{private_key[0]},{private_key[1]}"			)


if __name__ == "__main__":
	main()





