





import string

import numpy







def 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    int:
  return b if a == 0 else greatest_common_divisor(b % a					,					__UpperCAmelCase)







class     __snake_case       :





       '''simple docstring'''







       lowerCAmelCase__      		=     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)
       lowerCAmelCase__      		=     numpy.vectorize(lambda __lowerCamelCase			: x % 36			)

       lowerCAmelCase__      		=     numpy.vectorize(__lowerCamelCase			)




       def __init__(  self :    List[Any]							,				A :    Union[str, Any]		):
         __snake_case:						Union[str, Any]   =						self.modulus(A		)  # mod36 calc's on the encrypt key
         self.check_determinant()  # validate the determinant of the encryption key
         __snake_case:						Optional[Any]   =						encrypt_key.shape[0]




       def 							UpperCAmelCase__ (  self :    List[str]							,				A :    Optional[Any]		):
         return self.key_string.index(A		)




       def 							UpperCAmelCase__ (  self :    str							,				A :    Tuple		):
         return self.key_string[round(A		)]




       def 							UpperCAmelCase__ (  self :    Union[str, Any]		):
         __snake_case:						Any   =						round(numpy.linalg.det(self.encrypt_key		)		)

         if det < 0:
           __snake_case:						str   =						det % len(self.key_string		)

         __snake_case:						List[Any]   =						len(self.key_string		)
         if greatest_common_divisor(A							,				len(self.key_string		)		) != 1:
           __snake_case:						Dict   =						(
               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 							UpperCAmelCase__ (  self :    List[Any]							,				A :    int		):
         __snake_case:						Any   =						[char for char in text.upper() if char in self.key_string]

         __snake_case:						Tuple   =						chars[-1]
         while len(A		) % self.break_key != 0:
           chars.append(A		)

         return "".join(A		)




       def 							UpperCAmelCase__ (  self :    Union[str, Any]							,				A :    List[str]		):
         __snake_case:						int   =						self.process_text(text.upper()		)
         __snake_case:						List[Any]   =						''''''

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

         return encrypted




       def 							UpperCAmelCase__ (  self :    Any		):
         __snake_case:						int   =						round(numpy.linalg.det(self.encrypt_key		)		)

         if det < 0:
           __snake_case:						List[Any]   =						det % len(self.key_string		)
         __snake_case:						Any   =						None
         for i in range(len(self.key_string		)		):
           if (det * i) % len(self.key_string		) == 1:
             __snake_case:						Any   =						i
             break

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

         return self.to_int(self.modulus(A		)		)






       def 							UpperCAmelCase__ (  self :    Optional[int]							,				A :    int		):
         __snake_case:						Union[str, Any]   =						self.make_decrypt_key()
         __snake_case:						Tuple   =						self.process_text(text.upper()		)
         __snake_case:						Dict   =						''''''

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

         return decrypted







def 			A__							(    )   ->    None:
  __snake_case:						Dict   =						int(input("""Enter the order of the encryption key: """))
  __snake_case:						List[Any]   =						[]

  print("""Enter each row of the encryption key with space separated integers""")
  for _ in range(__UpperCAmelCase):
    __snake_case:						List[Any]   =						[int(__UpperCAmelCase) for x in input().split()]
    hill_matrix.append(__UpperCAmelCase)

  __snake_case:						Optional[Any]   =						HillCipher(numpy.array(__UpperCAmelCase))

  print("""Would you like to encrypt or decrypt some text? (1 or 2)""")
  __snake_case:						Union[str, Any]   =						input("""\n1. Encrypt\n2. Decrypt\n""")
  if option == "1":
    __snake_case:						List[str]   =						input("""What text would you like to encrypt?: """)
    print("""Your encrypted text is:""")
    print(hc.encrypt(__UpperCAmelCase))
  elif option == "2":
    __snake_case:						List[Any]   =						input("""What text would you like to decrypt?: """)
    print("""Your decrypted text is:""")
    print(hc.decrypt(__UpperCAmelCase))


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      main()













from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


UpperCAmelCase_     							= logging.get_logger(__name__)






class     lowercase__       (	__lowerCamelCase				):

   '''simple docstring'''


   a						:							str   		=		["pixel_values"]




   def __init__(    self,		__magic_name__ = True,		__magic_name__ = 32,		__magic_name__=PILImageResampling.BILINEAR,		__magic_name__ = True,		**__magic_name__,		) ->      None:






       """simple docstring"""
       UpperCamelCase__							:				int          =      do_resize
       UpperCamelCase__							:				Tuple          =      do_rescale
       UpperCamelCase__							:				Any          =      size_divisor
       UpperCamelCase__							:				List[Any]          =      resample
       super().__init__(**__magic_name__							)




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






       """simple docstring"""
       UpperCamelCase__   ,UpperCamelCase__							:				List[Any]          =      get_image_size(__magic_name__							)
       # Rounds the height and width down to the closest multiple of size_divisor
       UpperCamelCase__							:				Any          =      height // size_divisor * size_divisor
       UpperCamelCase__							:				Optional[int]          =      width // size_divisor * size_divisor
       UpperCamelCase__							:				str          =      resize(__magic_name__,		(new_h, new_w),		resample=__magic_name__,		data_format=__magic_name__,		**__magic_name__							)
       return image




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






       """simple docstring"""
       return rescale(image=__magic_name__,		scale=__magic_name__,		data_format=__magic_name__,		**__magic_name__							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__ = None,		__magic_name__ = None,		__magic_name__=None,		__magic_name__ = None,		__magic_name__ = None,		__magic_name__ = ChannelDimension.FIRST,		**__magic_name__,		) ->      BatchFeature:






       """simple docstring"""
       UpperCamelCase__							:				str          =      do_resize if do_resize is not None else self.do_resize
       UpperCamelCase__							:				Union[str, Any]          =      do_rescale if do_rescale is not None else self.do_rescale
       UpperCamelCase__							:				Any          =      size_divisor if size_divisor is not None else self.size_divisor
       UpperCamelCase__							:				str          =      resample if resample is not None else self.resample

       if do_resize and size_divisor is None:
           raise ValueError('''size_divisor is required for resizing'''							)

       UpperCamelCase__							:				Union[str, Any]          =      make_list_of_images(__magic_name__							)

       if not valid_images(__magic_name__							):
           raise ValueError('''Invalid image(s)'''							)

       # All transformations expect numpy arrays.
       UpperCamelCase__							:				Optional[Any]          =      [to_numpy_array(__magic_name__							) for img in images]

       if do_resize:
           UpperCamelCase__							:				str          =      [self.resize(__magic_name__,		size_divisor=__magic_name__,		resample=__magic_name__							) for image in images]

       if do_rescale:
           UpperCamelCase__							:				List[Any]          =      [self.rescale(__magic_name__,		scale=1 / 255							) for image in images]

       UpperCamelCase__							:				Optional[Any]          =      [to_channel_dimension_format(__magic_name__,		__magic_name__							) for image in images]

       UpperCamelCase__							:				Tuple          =      {'''pixel_values''': images}
       return BatchFeature(data=__magic_name__,		tensor_type=__magic_name__							)

