


'''simple docstring'''



import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import OwlViTImageProcessor



class       a							(						unittest.TestCase			):


     """simple docstring"""






     def __init__(							self	:						int				,					snake_case	:						List[Any]				,					snake_case	:						List[Any]=7				,					snake_case	:						str=3				,					snake_case	:						Union[str, Any]=18				,					snake_case	:						int=30				,					snake_case	:						Any=400				,					snake_case	:						Optional[Any]=True				,					snake_case	:						Union[str, Any]=None				,					snake_case	:						Optional[int]=True				,					snake_case	:						int=None				,					snake_case	:						Optional[Any]=True				,					snake_case	:						Tuple=[0.48_145_466, 0.4_578_275, 0.40_821_073]				,					snake_case	:						Optional[Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]				,					snake_case	:						Optional[int]=True				,					)		->				int:
          __UpperCAmelCase      :					Optional[Any]    				=     parent
          __UpperCAmelCase      :					Union[str, Any]    				=     batch_size
          __UpperCAmelCase      :					Optional[Any]    				=     num_channels
          __UpperCAmelCase      :					Dict    				=     image_size
          __UpperCAmelCase      :					Any    				=     min_resolution
          __UpperCAmelCase      :					List[str]    				=     max_resolution
          __UpperCAmelCase      :					List[Any]    				=     do_resize
          __UpperCAmelCase      :					Optional[int]    				=     size if size is not None else {'''height''': 18, '''width''': 18}
          __UpperCAmelCase      :					List[str]    				=     do_center_crop
          __UpperCAmelCase      :					Tuple    				=     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
          __UpperCAmelCase      :					str    				=     do_normalize
          __UpperCAmelCase      :					str    				=     image_mean
          __UpperCAmelCase      :					List[str]    				=     image_std
          __UpperCAmelCase      :					str    				=     do_convert_rgb






     def 					lowerCamelCase__					(							self	:						Dict     )		->				str:
          return {
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_convert_rgb": self.do_convert_rgb,
          }



@require_torch
@require_vision
class       a							(						__lowerCAmelCase      ,    unittest.TestCase			):


     """simple docstring"""






     SCREAMING_SNAKE_CASE			:					List[Any]				  =  OwlViTImageProcessor if is_vision_available() else None

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Any:
          __UpperCAmelCase      :					List[str]    				=     OwlViTImageProcessingTester(self     )

     @property
     def 					lowerCamelCase__					(							self	:						str     )		->				str:
          return self.image_processor_tester.prepare_image_processor_dict()

     def 					lowerCamelCase__					(							self	:						int     )		->				Union[str, Any]:
          __UpperCAmelCase      :					Optional[int]    				=     self.image_processing_class(**self.image_processor_dict     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''do_resize'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''size'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''do_center_crop'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''center_crop'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''do_normalize'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''image_mean'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''image_std'''     )     )
          self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,					'''do_convert_rgb'''     )     )

     def 					lowerCamelCase__					(							self	:						Dict     )		->				Dict:
          __UpperCAmelCase      :					Union[str, Any]    				=     self.image_processing_class.from_dict(self.image_processor_dict     )
          self.assertEqual(image_processor.size				,					{'''height''': 18, '''width''': 18}     )
          self.assertEqual(image_processor.crop_size				,					{'''height''': 18, '''width''': 18}     )

          __UpperCAmelCase      :					Optional[Any]    				=     self.image_processing_class.from_dict(self.image_processor_dict				,					size=42				,					crop_size=84     )
          self.assertEqual(image_processor.size				,					{'''height''': 42, '''width''': 42}     )
          self.assertEqual(image_processor.crop_size				,					{'''height''': 84, '''width''': 84}     )

     def 					lowerCamelCase__					(							self	:						Dict     )		->				Dict:
          __UpperCAmelCase      :					List[Any]    				=     self.image_processing_class(**self.image_processor_dict     )
          # create random PIL images
          __UpperCAmelCase      :					Tuple    				=     prepare_image_inputs(self.image_processor_tester				,					equal_resolution=__SCREAMING_SNAKE_CASE     )

          for image in image_inputs:
               self.assertIsInstance(__SCREAMING_SNAKE_CASE				,					Image.Image     )

          # Test not batched input
          __UpperCAmelCase      :					Dict    				=     image_processing(image_inputs[0]				,					return_tensors='''pt'''     ).pixel_values
          self.assertEqual(
              encoded_images.shape				,					(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )				,					)

          # Test batched
          __UpperCAmelCase      :					str    				=     image_processing(__SCREAMING_SNAKE_CASE				,					return_tensors='''pt'''     ).pixel_values
          self.assertEqual(
              encoded_images.shape				,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )				,					)

     def 					lowerCamelCase__					(							self	:						Any     )		->				Optional[Any]:
          __UpperCAmelCase      :					Union[str, Any]    				=     self.image_processing_class(**self.image_processor_dict     )
          # create random numpy tensors
          __UpperCAmelCase      :					int    				=     prepare_image_inputs(self.image_processor_tester				,					equal_resolution=__SCREAMING_SNAKE_CASE				,					numpify=__SCREAMING_SNAKE_CASE     )
          for image in image_inputs:
               self.assertIsInstance(__SCREAMING_SNAKE_CASE				,					np.ndarray     )

          # Test not batched input
          __UpperCAmelCase      :					Any    				=     image_processing(image_inputs[0]				,					return_tensors='''pt'''     ).pixel_values
          self.assertEqual(
              encoded_images.shape				,					(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )				,					)

          # Test batched
          __UpperCAmelCase      :					Any    				=     image_processing(__SCREAMING_SNAKE_CASE				,					return_tensors='''pt'''     ).pixel_values
          self.assertEqual(
              encoded_images.shape				,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )				,					)






     def 					lowerCamelCase__					(							self	:						Any     )		->				int:
          __UpperCAmelCase      :					Optional[Any]    				=     self.image_processing_class(**self.image_processor_dict     )
          # create random PyTorch tensors
          __UpperCAmelCase      :					Dict    				=     prepare_image_inputs(self.image_processor_tester				,					equal_resolution=__SCREAMING_SNAKE_CASE				,					torchify=__SCREAMING_SNAKE_CASE     )
          for image in image_inputs:
               self.assertIsInstance(__SCREAMING_SNAKE_CASE				,					torch.Tensor     )

          # Test not batched input
          __UpperCAmelCase      :					str    				=     image_processing(image_inputs[0]				,					return_tensors='''pt'''     ).pixel_values
          self.assertEqual(
              encoded_images.shape				,					(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )				,					)

          # Test batched
          __UpperCAmelCase      :					Optional[Any]    				=     image_processing(__SCREAMING_SNAKE_CASE				,					return_tensors='''pt'''     ).pixel_values
          self.assertEqual(
              encoded_images.shape				,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )				,					)






"""simple docstring"""


a__       :  Optional[Any]       		=					{
    """A""": ("""ABCDEFGHIJKLM""", """NOPQRSTUVWXYZ"""),
    """B""": ("""ABCDEFGHIJKLM""", """NOPQRSTUVWXYZ"""),
    """C""": ("""ABCDEFGHIJKLM""", """ZNOPQRSTUVWXY"""),
    """D""": ("""ABCDEFGHIJKLM""", """ZNOPQRSTUVWXY"""),
    """E""": ("""ABCDEFGHIJKLM""", """YZNOPQRSTUVWX"""),
    """F""": ("""ABCDEFGHIJKLM""", """YZNOPQRSTUVWX"""),
    """G""": ("""ABCDEFGHIJKLM""", """XYZNOPQRSTUVW"""),
    """H""": ("""ABCDEFGHIJKLM""", """XYZNOPQRSTUVW"""),
    """I""": ("""ABCDEFGHIJKLM""", """WXYZNOPQRSTUV"""),
    """J""": ("""ABCDEFGHIJKLM""", """WXYZNOPQRSTUV"""),
    """K""": ("""ABCDEFGHIJKLM""", """VWXYZNOPQRSTU"""),
    """L""": ("""ABCDEFGHIJKLM""", """VWXYZNOPQRSTU"""),
    """M""": ("""ABCDEFGHIJKLM""", """UVWXYZNOPQRST"""),
    """N""": ("""ABCDEFGHIJKLM""", """UVWXYZNOPQRST"""),
    """O""": ("""ABCDEFGHIJKLM""", """TUVWXYZNOPQRS"""),
    """P""": ("""ABCDEFGHIJKLM""", """TUVWXYZNOPQRS"""),
    """Q""": ("""ABCDEFGHIJKLM""", """STUVWXYZNOPQR"""),
    """R""": ("""ABCDEFGHIJKLM""", """STUVWXYZNOPQR"""),
    """S""": ("""ABCDEFGHIJKLM""", """RSTUVWXYZNOPQ"""),
    """T""": ("""ABCDEFGHIJKLM""", """RSTUVWXYZNOPQ"""),
    """U""": ("""ABCDEFGHIJKLM""", """QRSTUVWXYZNOP"""),
    """V""": ("""ABCDEFGHIJKLM""", """QRSTUVWXYZNOP"""),
    """W""": ("""ABCDEFGHIJKLM""", """PQRSTUVWXYZNO"""),
    """X""": ("""ABCDEFGHIJKLM""", """PQRSTUVWXYZNO"""),
    """Y""": ("""ABCDEFGHIJKLM""", """OPQRSTUVWXYZN"""),
    """Z""": ("""ABCDEFGHIJKLM""", """OPQRSTUVWXYZN"""),
}





def 				a__      (	_UpperCAmelCase						)     ->	list[tuple[str, str]]:

 '''simple docstring'''






 return [alphabet[char] for char in key.upper()]





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 snake_case__     				=					""
 snake_case__     				=					0
 snake_case__     				=					generate_table(_UpperCAmelCase						)
 for char in words.upper():
  cipher += get_opponent(table[count]						,  _UpperCAmelCase						)
  snake_case__     				=					(count + 1) % len(_UpperCAmelCase						)
 return cipher





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 return encrypt(_UpperCAmelCase						,  _UpperCAmelCase						)





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	tuple[int, int]:

 '''simple docstring'''






 snake_case__     				=					0 if char in table[0] else 1
 snake_case__     				=					table[row].index(_UpperCAmelCase						)
 return row, col





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 snake_case__				, snake_case__     				=					get_position(_UpperCAmelCase						,  char.upper()						)
 if row == 1:
  return table[0][col]
 else:
  return table[1][col] if row == 0 else char


if __name__ == "__main__":
   import doctest

   doctest.testmod()  # Fist ensure that all our tests are passing...
   a__       :  int       		=					input("""Enter key: """).strip()
   a__       :  Optional[int]       		=					input("""Enter text to encrypt: """).strip()
   a__       :  Dict       		=					encrypt(key, text)

   print(f'''Encrypted: {cipher_text}''')
   print(f'''Decrypted with key: {decrypt(key, cipher_text)}''')

