import string

import numpy







def      _a					(   lowercase__	:      int  ,	lowercase__	:      int			):







     '''simple docstring'''


     return b if a == 0 else greatest_common_divisor(b % a  ,	lowercase__			)

class    snake_case       :
  lowercase_								=  string.ascii_uppercase + string.digits
  # This cipher takes alphanumerics into account
  # i.e. a total of 36 characters

  # take x and return x % len(key_string)
  lowercase_								=  numpy.vectorize(lambda UpperCamelCase_    : x % 36    )

  lowercase_								=  numpy.vectorize(UpperCamelCase_    )




  def __init__(   self  :						Tuple  ,			a_  :						numpy.ndarray					)->							None:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__					:					Any      =		self.modulus(a_					)  # mod36 calc's on the encrypt key
       self.check_determinant()  # validate the determinant of the encryption key
       SCREAMING_SNAKE_CASE__					:					int      =		encrypt_key.shape[0]




  def 						__lowercase(   self  :						Any  ,			a_  :						str					)->							int:




       """simple docstring"""
       return self.key_string.index(a_					)




  def 						__lowercase(   self  :						int  ,			a_  :						int					)->							str:




       """simple docstring"""
       return self.key_string[round(a_					)]




  def 						__lowercase(   self  :						Dict					)->							None:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__					:					Any      =		round(numpy.linalg.det(self.encrypt_key					)					)

       if det < 0:
            SCREAMING_SNAKE_CASE__					:					List[Any]      =		det % len(self.key_string					)

       SCREAMING_SNAKE_CASE__					:					Tuple      =		len(self.key_string					)
       if greatest_common_divisor(a_  ,			len(self.key_string					)					) != 1:
            SCREAMING_SNAKE_CASE__					:					Any      =		(
                F'''determinant modular {req_l} of encryption key({det}) '''
                F'''is not co prime w.r.t {req_l}.\nTry another key.'''
            )
            raise ValueError(a_					)




  def 						__lowercase(   self  :						int  ,			a_  :						str					)->							str:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__					:					Optional[int]      =		[char for char in text.upper() if char in self.key_string]

       SCREAMING_SNAKE_CASE__					:					str      =		chars[-1]
       while len(a_					) % self.break_key != 0:
            chars.append(a_					)

       return "".join(a_					)




  def 						__lowercase(   self  :						Any  ,			a_  :						str					)->							str:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__					:					Tuple      =		self.process_text(text.upper()					)
       SCREAMING_SNAKE_CASE__					:					int      =		''

       for i in range(0  ,			len(a_					) - self.break_key + 1  ,			self.break_key					):
            SCREAMING_SNAKE_CASE__					:					Any      =		text[i : i + self.break_key]
            SCREAMING_SNAKE_CASE__					:					int      =		[self.replace_letters(a_					) for char in batch]
            SCREAMING_SNAKE_CASE__					:					int      =		numpy.array([vec]					).T
            SCREAMING_SNAKE_CASE__					:					Tuple      =		self.modulus(self.encrypt_key.dot(a_					)					).T.tolist()[
                0
            ]
            SCREAMING_SNAKE_CASE__					:					List[str]      =		''.join(
                self.replace_digits(a_					) for num in batch_encrypted					)
            encrypted += encrypted_batch

       return encrypted




  def 						__lowercase(   self  :						List[str]					)->							numpy.ndarray:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__					:					Any      =		round(numpy.linalg.det(self.encrypt_key					)					)

       if det < 0:
            SCREAMING_SNAKE_CASE__					:					Any      =		det % len(self.key_string					)
       SCREAMING_SNAKE_CASE__					:					Dict      =		None
       for i in range(len(self.key_string					)					):
            if (det * i) % len(self.key_string					) == 1:
                 SCREAMING_SNAKE_CASE__					:					Any      =		i
                 break

       SCREAMING_SNAKE_CASE__					:					Optional[int]      =		(
           det_inv
           * numpy.linalg.det(self.encrypt_key					)
           * numpy.linalg.inv(self.encrypt_key					)
       )

       return self.to_int(self.modulus(a_					)					)




  def 						__lowercase(   self  :						Dict  ,			a_  :						str					)->							str:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__					:					int      =		self.make_decrypt_key()
       SCREAMING_SNAKE_CASE__					:					Optional[int]      =		self.process_text(text.upper()					)
       SCREAMING_SNAKE_CASE__					:					List[str]      =		''

       for i in range(0  ,			len(a_					) - self.break_key + 1  ,			self.break_key					):
            SCREAMING_SNAKE_CASE__					:					int      =		text[i : i + self.break_key]
            SCREAMING_SNAKE_CASE__					:					Optional[int]      =		[self.replace_letters(a_					) for char in batch]
            SCREAMING_SNAKE_CASE__					:					Any      =		numpy.array([vec]					).T
            SCREAMING_SNAKE_CASE__					:					str      =		self.modulus(decrypt_key.dot(a_					)					).T.tolist()[0]
            SCREAMING_SNAKE_CASE__					:					int      =		''.join(
                self.replace_digits(a_					) for num in batch_decrypted					)
            decrypted += decrypted_batch

       return decrypted







def      _a					(   ):







     '''simple docstring'''


     SCREAMING_SNAKE_CASE__					:					Dict      =		int(input('Enter the order of the encryption key: '			)			)
     SCREAMING_SNAKE_CASE__					:					Dict      =		[]

     print('Enter each row of the encryption key with space separated integers'			)
     for _ in range(lowercase__			):
          SCREAMING_SNAKE_CASE__					:					Tuple      =		[int(lowercase__			) for x in input().split()]
          hill_matrix.append(lowercase__			)

     SCREAMING_SNAKE_CASE__					:					Any      =		HillCipher(numpy.array(lowercase__			)			)

     print('Would you like to encrypt or decrypt some text? (1 or 2)'			)
     SCREAMING_SNAKE_CASE__					:					Optional[Any]      =		input('\n1. Encrypt\n2. Decrypt\n'			)
     if option == "1":
          SCREAMING_SNAKE_CASE__					:					Any      =		input('What text would you like to encrypt?: '			)
          print('Your encrypted text is:'			)
          print(hc.encrypt(lowercase__			)			)
     elif option == "2":
          SCREAMING_SNAKE_CASE__					:					int      =		input('What text would you like to decrypt?: '			)
          print('Your decrypted text is:'			)
          print(hc.decrypt(lowercase__			)			)


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      main()










from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
							import PIL

UpperCAmelCase_							=				logging.get_logger(__name__)





def  __magic_name__  (				lowercase				)				-> List[List[ImageInput]]:

							"""simple docstring"""



							if isinstance(lowercase				,       (list, tuple)				) and isinstance(videos[0]				,       (list, tuple)				) and is_valid_image(videos[0][0]				):
														return videos

							elif isinstance(lowercase				,       (list, tuple)				) and is_valid_image(videos[0]				):
														return [videos]

							elif is_valid_image(lowercase				):
														return [[videos]]

							raise ValueError(f"""Could not make batched video from {videos}"""				)




class     UpperCamelCase__					(     lowerCamelCase__				):






		'''simple docstring'''






		__a       :       List[Any]       =	["""pixel_values"""]






		def __init__(							self,   snake_case__ = True,   snake_case__ = None,   snake_case__ = PILImageResampling.BILINEAR,   snake_case__ = True,   snake_case__ = None,   snake_case__ = True,   snake_case__ = 1 / 2_55,   snake_case__ = True,   snake_case__ = True,   snake_case__ = None,   snake_case__ = None,   **snake_case__,   )       -> None:






									"""simple docstring"""
									super().__init__(**snake_case__  )
									lowercase_	:   str  				=     size if size is not None else {"""shortest_edge""": 2_56}
									lowercase_	:   int  				=     get_size_dict(snake_case__,   default_to_square=snake_case__  )
									lowercase_	:   int  				=     crop_size if crop_size is not None else {"""height""": 2_24, """width""": 2_24}
									lowercase_	:   Optional[int]  				=     get_size_dict(snake_case__,   param_name="""crop_size"""  )

									lowercase_	:   List[Any]  				=     do_resize
									lowercase_	:   int  				=     size
									lowercase_	:   int  				=     do_center_crop
									lowercase_	:   Optional[Any]  				=     crop_size
									lowercase_	:   str  				=     resample
									lowercase_	:   Any  				=     do_rescale
									lowercase_	:   Dict  				=     rescale_factor
									lowercase_	:   List[Any]  				=     offset
									lowercase_	:   int  				=     do_normalize
									lowercase_	:   str  				=     image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
									lowercase_	:   Tuple  				=     image_std if image_std is not None else IMAGENET_STANDARD_STD






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__ = PILImageResampling.BILINEAR,   snake_case__ = None,   **snake_case__,   )       -> np.ndarray:






									"""simple docstring"""
									lowercase_	:   int  				=     get_size_dict(snake_case__,   default_to_square=snake_case__  )
									if "shortest_edge" in size:
																lowercase_	:   Union[str, Any]  				=     get_resize_output_image_size(snake_case__,   size["""shortest_edge"""],   default_to_square=snake_case__  )
									elif "height" in size and "width" in size:
																lowercase_	:   Dict  				=     (size["""height"""], size["""width"""])
									else:
																raise ValueError(f"""Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"""  )
									return resize(snake_case__,   size=snake_case__,   resample=snake_case__,   data_format=snake_case__,   **snake_case__  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__ = None,   **snake_case__,   )       -> np.ndarray:






									"""simple docstring"""
									lowercase_	:   List[Any]  				=     get_size_dict(snake_case__  )
									if "height" not in size or "width" not in size:
																raise ValueError(f"""Size must have 'height' and 'width' as keys. Got {size.keys()}"""  )
									return center_crop(snake_case__,   size=(size["""height"""], size["""width"""]),   data_format=snake_case__,   **snake_case__  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__ = True,   snake_case__ = None,   **snake_case__,   )       -> str:






									"""simple docstring"""
									lowercase_	:   Dict  				=     image.astype(np.floataa  )
									if offset:
																lowercase_	:   Optional[Any]  				=     image - (scale / 2)
									return rescale(snake_case__,   scale=snake_case__,   data_format=snake_case__,   **snake_case__  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__ = None,   **snake_case__,   )       -> np.ndarray:






									"""simple docstring"""
									return normalize(snake_case__,   mean=snake_case__,   std=snake_case__,   data_format=snake_case__,   **snake_case__  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = ChannelDimension.FIRST,   )       -> np.ndarray:






									"""simple docstring"""
									if do_resize and size is None or resample is None:
																raise ValueError("""Size and resample must be specified if do_resize is True."""  )

									if do_center_crop and crop_size is None:
																raise ValueError("""Crop size must be specified if do_center_crop is True."""  )

									if do_rescale and rescale_factor is None:
																raise ValueError("""Rescale factor must be specified if do_rescale is True."""  )

									if do_normalize and (image_mean is None or image_std is None):
																raise ValueError("""Image mean and std must be specified if do_normalize is True."""  )

									if offset and not do_rescale:
																raise ValueError("""For offset, do_rescale must also be set to True."""  )

									# All transformations expect numpy arrays.
									lowercase_	:   Optional[int]  				=     to_numpy_array(snake_case__  )

									if do_resize:
																lowercase_	:   Dict  				=     self.resize(image=snake_case__,   size=snake_case__,   resample=snake_case__  )

									if do_center_crop:
																lowercase_	:   Optional[int]  				=     self.center_crop(snake_case__,   size=snake_case__  )

									if do_rescale:
																lowercase_	:   Dict  				=     self.rescale(image=snake_case__,   scale=snake_case__,   offset=snake_case__  )

									if do_normalize:
																lowercase_	:   Optional[Any]  				=     self.normalize(image=snake_case__,   mean=snake_case__,   std=snake_case__  )

									lowercase_	:   Tuple  				=     to_channel_dimension_format(snake_case__,   snake_case__  )
									return image






		def 						snake_case__				(							self,   snake_case__,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = ChannelDimension.FIRST,   **snake_case__,   )       -> PIL.Image.Image:






									"""simple docstring"""
									lowercase_	:   Any  				=     do_resize if do_resize is not None else self.do_resize
									lowercase_	:   str  				=     resample if resample is not None else self.resample
									lowercase_	:   List[str]  				=     do_center_crop if do_center_crop is not None else self.do_center_crop
									lowercase_	:   Optional[Any]  				=     do_rescale if do_rescale is not None else self.do_rescale
									lowercase_	:   str  				=     rescale_factor if rescale_factor is not None else self.rescale_factor
									lowercase_	:   List[Any]  				=     offset if offset is not None else self.offset
									lowercase_	:   Optional[Any]  				=     do_normalize if do_normalize is not None else self.do_normalize
									lowercase_	:   Any  				=     image_mean if image_mean is not None else self.image_mean
									lowercase_	:   Optional[Any]  				=     image_std if image_std is not None else self.image_std

									lowercase_	:   Optional[Any]  				=     size if size is not None else self.size
									lowercase_	:   Dict  				=     get_size_dict(snake_case__,   default_to_square=snake_case__  )
									lowercase_	:   Union[str, Any]  				=     crop_size if crop_size is not None else self.crop_size
									lowercase_	:   Tuple  				=     get_size_dict(snake_case__,   param_name="""crop_size"""  )

									if not valid_images(snake_case__  ):
																raise ValueError(
																    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
																    """torch.Tensor, tf.Tensor or jax.ndarray."""  )

									lowercase_	:   Optional[Any]  				=     make_batched(snake_case__  )

									lowercase_	:   Optional[Any]  				=     [
									    [
									        self._preprocess_image(
									            image=snake_case__,   do_resize=snake_case__,   size=snake_case__,   resample=snake_case__,   do_center_crop=snake_case__,   crop_size=snake_case__,   do_rescale=snake_case__,   rescale_factor=snake_case__,   offset=snake_case__,   do_normalize=snake_case__,   image_mean=snake_case__,   image_std=snake_case__,   data_format=snake_case__,   )
									        for img in video
									    ]
									    for video in videos
									]

									lowercase_	:   List[str]  				=     {"""pixel_values""": videos}
									return BatchFeature(data=snake_case__,   tensor_type=snake_case__  )