





"""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 ViTImageProcessor



class    lowercase_ (   unittest.TestCase							):

       def __init__(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE=7      ,    __SCREAMING_SNAKE_CASE=3      ,    __SCREAMING_SNAKE_CASE=18      ,    __SCREAMING_SNAKE_CASE=30      ,    __SCREAMING_SNAKE_CASE=400      ,    __SCREAMING_SNAKE_CASE=True      ,    __SCREAMING_SNAKE_CASE=None      ,    __SCREAMING_SNAKE_CASE=True      ,    __SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]      ,    __SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]      ,    ):






        '''simple docstring'''

        snake_case__										= size if size is not None else {"height": 18, "width": 18}
        snake_case__										= parent
        snake_case__										= batch_size
        snake_case__										= num_channels
        snake_case__										= image_size
        snake_case__										= min_resolution
        snake_case__										= max_resolution
        snake_case__										= do_resize
        snake_case__										= size
        snake_case__										= do_normalize
        snake_case__										= image_mean
        snake_case__										= image_std

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
        }



@require_torch
@require_vision
class    lowercase_ (   __lowerCAmelCase ,unittest.TestCase							):
       snake_case__ :							Tuple 							=   ViTImageProcessor if is_vision_available() else None

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= ViTImageProcessingTester(self   )

       @property
       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        return self.image_processor_tester.prepare_image_processor_dict()

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.image_processing_class(**self.image_processor_dict   )
        self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,    "image_mean"   )   )
        self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,    "image_std"   )   )
        self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,    "do_normalize"   )   )
        self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,    "do_resize"   )   )
        self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,    "size"   )   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.image_processing_class.from_dict(self.image_processor_dict   )
        self.assertEqual(image_processor.size      ,    {"height": 18, "width": 18}   )

        snake_case__										= self.image_processing_class.from_dict(self.image_processor_dict      ,    size=42   )
        self.assertEqual(image_processor.size      ,    {"height": 42, "width": 42}   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        pass

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.image_processing_class(**self.image_processor_dict   )
        # create random PIL images
        snake_case__										= 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
        snake_case__										= 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.size["height"],
                self.image_processor_tester.size["width"],
            )      ,    )

        # Test batched
        snake_case__										= 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.size["height"],
                self.image_processor_tester.size["width"],
            )      ,    )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.image_processing_class(**self.image_processor_dict   )
        # create random numpy tensors
        snake_case__										= 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
        snake_case__										= 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.size["height"],
                self.image_processor_tester.size["width"],
            )      ,    )

        # Test batched
        snake_case__										= 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.size["height"],
                self.image_processor_tester.size["width"],
            )      ,    )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.image_processing_class(**self.image_processor_dict   )
        # create random PyTorch tensors
        snake_case__										= 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
        snake_case__										= 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.size["height"],
                self.image_processor_tester.size["width"],
            )      ,    )

        # Test batched
        snake_case__										= 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.size["height"],
                self.image_processor_tester.size["width"],
            )      ,    )








"""simple docstring"""


import random
import sys

from . import cryptomath_module as cryptomath

a__    :   int    						= (
    r""" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"""
    r"""abcdefghijklmnopqrstuvwxyz{|}~"""
)





def 							a__	(     _UpperCAmelCase		,   _UpperCAmelCase		,   _UpperCAmelCase		)			->     None:

 '''simple docstring'''






 if mode == "encrypt":
  if key_a == 1:
   sys.exit(
       "The affine cipher becomes weak when key "
       "A is set to 1. Choose different key"		)
  if key_b == 0:
   sys.exit(
       "The affine cipher becomes weak when key "
       "B is set to 0. Choose different key"		)
 if key_a < 0 or key_b < 0 or key_b > len(_UpperCAmelCase		) - 1:
  sys.exit(
      "Key A must be greater than 0 and key B must "
      f"be between 0 and {len(_UpperCAmelCase		) - 1}."		)
 if cryptomath.gcd(_UpperCAmelCase		,   len(_UpperCAmelCase		)		) != 1:
  sys.exit(
      f"Key A {key_a} and the symbol set size {len(_UpperCAmelCase		)} "
      "are not relatively prime. Choose a different key."		)





def 							a__	(     _UpperCAmelCase		,   _UpperCAmelCase		)			->     str:

 '''simple docstring'''






 snake_case__							,      snake_case__										= divmod(_UpperCAmelCase		,   len(_UpperCAmelCase		)		)
 check_keys(_UpperCAmelCase		,   _UpperCAmelCase		,   "encrypt"		)
 snake_case__										= ""
 for symbol in message:
  if symbol in SYMBOLS:
   snake_case__										= SYMBOLS.find(_UpperCAmelCase		)
   cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(_UpperCAmelCase		)]
  else:
   cipher_text += symbol
 return cipher_text





def 							a__	(     _UpperCAmelCase		,   _UpperCAmelCase		)			->     str:

 '''simple docstring'''






 snake_case__							,      snake_case__										= divmod(_UpperCAmelCase		,   len(_UpperCAmelCase		)		)
 check_keys(_UpperCAmelCase		,   _UpperCAmelCase		,   "decrypt"		)
 snake_case__										= ""
 snake_case__										= cryptomath.find_mod_inverse(_UpperCAmelCase		,   len(_UpperCAmelCase		)		)
 for symbol in message:
  if symbol in SYMBOLS:
   snake_case__										= SYMBOLS.find(_UpperCAmelCase		)
   plain_text += SYMBOLS[
       (sym_index - key_b) * mod_inverse_of_key_a % len(_UpperCAmelCase		)
   ]
  else:
   plain_text += symbol
 return plain_text





def 							a__	(     )			->     int:

 '''simple docstring'''






 while True:
  snake_case__										= random.randint(2		,   len(_UpperCAmelCase		)		)
  snake_case__										= random.randint(2		,   len(_UpperCAmelCase		)		)
  if cryptomath.gcd(_UpperCAmelCase		,   len(_UpperCAmelCase		)		) == 1 and key_b % len(_UpperCAmelCase		) != 0:
   return key_b * len(_UpperCAmelCase		) + key_b





def 							a__	(     )			->     None:

 '''simple docstring'''






 snake_case__										= input("Enter message: "		).strip()
 snake_case__										= int(input("Enter key [2000 - 9000]: "		).strip()		)
 snake_case__										= input("Encrypt/Decrypt [E/D]: "		).strip().lower()

 if mode.startswith("e"		):
  snake_case__										= "encrypt"
  snake_case__										= encrypt_message(_UpperCAmelCase		,   _UpperCAmelCase		)
 elif mode.startswith("d"		):
  snake_case__										= "decrypt"
  snake_case__										= decrypt_message(_UpperCAmelCase		,   _UpperCAmelCase		)
 print(f"\n{mode.title()}ed text: \n{translated}"		)


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   # main()

