
import os
import random
import sys

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

def 		UpperCamelCase						(   )		->						None:


  '''simple docstring'''






  print("""Making key files...""" )
  make_key_files("""rsa"""			,			10_24 )
  print("""Key files generation successful.""" )

def 		UpperCamelCase						(   lowercase_ )		->						tuple[tuple[int, int], tuple[int, int]]:


  '''simple docstring'''






  print("""Generating prime p...""" )
  lowercase__	: Dict     		=   rabinMiller.generate_large_prime(lowercase_ )
  print("""Generating prime q...""" )
  lowercase__	: List[str]     		=   rabinMiller.generate_large_prime(lowercase_ )
  lowercase__	: int     		=   p * q

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

  print("""Calculating d that is mod inverse of e...""" )
  lowercase__	: Dict     		=   cryptoMath.find_mod_inverse(lowercase_			,			(p - 1) * (q - 1) )

  lowercase__	: Tuple     		=   (n, e)
  lowercase__	: Union[str, Any]     		=   (n, d)
  return (public_key, private_key)

def 		UpperCamelCase						(   lowercase_			,			lowercase_ )		->						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__	: List[Any]     		=   generate_key(lowercase_ )
  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()








from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding



class    _snake_case (						UpperCAmelCase_				):
 __lowerCAmelCase	:  Any	   =      ['image_processor', 'tokenizer']
 __lowerCAmelCase	:  Union[str, Any]	   =      'AutoImageProcessor'
 __lowerCAmelCase	:  int	   =      'AutoTokenizer'


 def __init__(       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   super().__init__(SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_)
   lowercase__	: Union[str, Any]     		=   self.image_processor


 def __call__(       self       ,	SCREAMING_SNAKE_CASE_=None       ,	SCREAMING_SNAKE_CASE_=None       ,	SCREAMING_SNAKE_CASE_=None       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   if text is None and images is None:
     raise ValueError("""You have to specify either text or images. Both cannot be none.""")

   if text is not None:
     lowercase__	: List[str]     		=   self.tokenizer(SCREAMING_SNAKE_CASE_       ,	return_tensors=SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_)

   if images is not None:
     lowercase__	: Optional[int]     		=   self.image_processor(SCREAMING_SNAKE_CASE_       ,	return_tensors=SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_)

   if text is not None and images is not None:
     lowercase__	: Union[str, Any]     		=   image_features.pixel_values
     return encoding
   elif text is not None:
     return encoding
   else:
     return BatchEncoding(data=dict(**SCREAMING_SNAKE_CASE_)       ,	tensor_type=SCREAMING_SNAKE_CASE_)


 def   lowercase__  (       self       ,	*SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_)


 def   lowercase__  (       self       ,	*SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   return self.tokenizer.decode(*SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_)



 @property
 def   lowercase__  (       self):


   '''simple docstring'''




   return ["input_ids", "attention_mask", "pixel_values"]






