


import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
		from transformers import TvltImageProcessor

if is_speech_available():
		from transformers import TvltFeatureExtractor

from transformers import TvltProcessor


@require_torch
class        lowerCAmelCase_			(							unittest.TestCase):




						def 			_snake_case       (						self    : List[Any]    )   ->Optional[int]:






									"""simple docstring"""






									a__			:List[str]    	=     """ZinengTang/tvlt-base"""
									a__			:List[Any]    	=     tempfile.mkdtemp()




						def 			_snake_case       (						self    : Tuple ,  **__A    : Union[str, Any]    )   ->str:






									"""simple docstring"""






									return TvltImageProcessor.from_pretrained(self.checkpoint ,  **__UpperCamelCase    )




						def 			_snake_case       (						self    : str ,  **__A    : int    )   ->List[str]:






									"""simple docstring"""






									return TvltFeatureExtractor.from_pretrained(self.checkpoint ,  **__UpperCamelCase    )




						def 			_snake_case       (						self    : int    )   ->str:






									"""simple docstring"""






									shutil.rmtree(self.tmpdirname    )




						def 			_snake_case       (						self    : str    )   ->Tuple:






									"""simple docstring"""






									a__			:int    	=     self.get_image_processor()
									a__			:str    	=     self.get_feature_extractor()

									a__			:Dict    	=     TvltProcessor(image_processor=__UpperCamelCase ,  feature_extractor=__UpperCamelCase    )
									processor.save_pretrained(self.tmpdirname    )
									a__			:List[Any]    	=     TvltProcessor.from_pretrained(self.tmpdirname    )

									self.assertIsInstance(processor.feature_extractor ,  __UpperCamelCase    )
									self.assertIsInstance(processor.image_processor ,  __UpperCamelCase    )




						def 			_snake_case       (						self    : Dict    )   ->List[str]:






									"""simple docstring"""






									a__			:str    	=     self.get_image_processor()
									a__			:int    	=     self.get_feature_extractor()

									a__			:Optional[int]    	=     TvltProcessor(image_processor=__UpperCamelCase ,  feature_extractor=__UpperCamelCase    )

									a__			:Optional[Any]    	=     np.ones([12000]    )

									a__			:Optional[Any]    	=     feature_extractor(__UpperCamelCase ,  return_tensors="np"    )
									a__			:Union[str, Any]    	=     processor(audio=__UpperCamelCase ,  return_tensors="np"    )

									for key in audio_dict.keys():
												self.assertAlmostEqual(audio_dict[key].sum() ,  input_processor[key].sum() ,  delta=1E-2    )




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






									"""simple docstring"""






									a__			:List[Any]    	=     self.get_image_processor()
									a__			:Any    	=     self.get_feature_extractor()

									a__			:str    	=     TvltProcessor(image_processor=__UpperCamelCase ,  feature_extractor=__UpperCamelCase    )

									a__			:Optional[Any]    	=     np.ones([3, 224, 224]    )

									a__			:Union[str, Any]    	=     image_processor(__UpperCamelCase ,  return_tensors="np"    )
									a__			:str    	=     processor(images=__UpperCamelCase ,  return_tensors="np"    )

									for key in image_dict.keys():
												self.assertAlmostEqual(image_dict[key].sum() ,  input_processor[key].sum() ,  delta=1E-2    )




						def 			_snake_case       (						self    : int    )   ->Tuple:






									"""simple docstring"""






									a__			:int    	=     self.get_image_processor()
									a__			:int    	=     self.get_feature_extractor()

									a__			:str    	=     TvltProcessor(image_processor=__UpperCamelCase ,  feature_extractor=__UpperCamelCase    )

									a__			:Optional[int]    	=     np.ones([12000]    )
									a__			:Union[str, Any]    	=     np.ones([3, 224, 224]    )

									a__			:List[Any]    	=     processor(audio=__UpperCamelCase ,  images=__UpperCamelCase    )

									self.assertListEqual(list(inputs.keys()    ) ,  ["audio_values", "audio_mask", "pixel_values", "pixel_mask"]    )

									# test if it raises when no input is passed
									with pytest.raises(__UpperCamelCase    ):
												processor()






						def 			_snake_case       (						self    : Tuple    )   ->List[Any]:






									"""simple docstring"""






									a__			:str    	=     self.get_image_processor()
									a__			:Union[str, Any]    	=     self.get_feature_extractor()

									a__			:Optional[Any]    	=     TvltProcessor(image_processor=__UpperCamelCase ,  feature_extractor=__UpperCamelCase    )

									self.assertListEqual(
									    processor.model_input_names ,  image_processor.model_input_names + feature_extractor.model_input_names ,  msg="`processor` and `image_processor`+`feature_extractor` model input names do not match" ,  )



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"""		, 1024			)
						print("""Key files generation successful."""			)






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				int			):
						print("""Generating prime p..."""			)
						UpperCamelCase_		:							Tuple  =		rabinMiller.generate_large_prime(_SCREAMING_SNAKE_CASE			)
						print("""Generating prime q..."""			)
						UpperCamelCase_		:							List[Any]  =		rabinMiller.generate_large_prime(_SCREAMING_SNAKE_CASE			)
						UpperCamelCase_		:							List[str]  =		p * q

						print("""Generating e that is relatively prime to (p - 1) * (q - 1)..."""			)
						while True:
												UpperCamelCase_		:							Union[str, Any]  =		random.randrange(2 ** (key_size - 1)		, 2 ** (key_size)			)
												if cryptoMath.gcd(_SCREAMING_SNAKE_CASE		, (p - 1) * (q - 1)			) == 1:
																		break

						print("""Calculating d that is mod inverse of e..."""			)
						UpperCamelCase_		:							Tuple  =		cryptoMath.find_mod_inverse(_SCREAMING_SNAKE_CASE		, (p - 1) * (q - 1)			)

						UpperCamelCase_		:							Tuple  =		(n, e)
						UpperCamelCase_		:							int  =		(n, d)
						return (public_key, private_key)






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

						UpperCamelCase_,UpperCamelCase_		:							str  =		generate_key(_SCREAMING_SNAKE_CASE			)
						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()






