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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import BlipImageProcessor
class      UpperCamelCase__(      unittest.TestCase			):





						def __init__(							self		,__UpperCAmelCase		,__UpperCAmelCase=7		,__UpperCAmelCase=3		,__UpperCAmelCase=18		,__UpperCAmelCase=30		,__UpperCAmelCase=4_00		,__UpperCAmelCase=True		,__UpperCAmelCase=None		,__UpperCAmelCase=True		,__UpperCAmelCase=False		,__UpperCAmelCase=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]		,__UpperCAmelCase=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]		,__UpperCAmelCase=True		,)       ->					Optional[int]:
													A__						  =				size if size is not None else {'height': 20, 'width': 20}
													A__						  =				parent
													A__						  =				batch_size
													A__						  =				num_channels
													A__						  =				image_size
													A__						  =				min_resolution
													A__						  =				max_resolution
													A__						  =				do_resize
													A__						  =				size
													A__						  =				do_normalize
													A__						  =				image_mean
													A__						  =				image_std
													A__						  =				do_pad
													A__						  =				do_convert_rgb





						def 					snake_case__						(							self  )       ->					List[Any]:
													return {
													    "do_resize": self.do_resize,
													    "size": self.size,
													    "do_normalize": self.do_normalize,
													    "image_mean": self.image_mean,
													    "image_std": self.image_std,
													    "do_convert_rgb": self.do_convert_rgb,
													    "do_pad": self.do_pad,
													}





						def 					snake_case__						(							self		,__UpperCAmelCase=False		,__UpperCAmelCase=False		,__UpperCAmelCase=False  )       ->					str:
													assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

													if equal_resolution:
																				A__						  =				[]
																				for i in range(self.batch_size  ):
																											image_inputs.append(
																											    np.random.randint(
																											        2_55		,size=(self.num_channels, self.max_resolution, self.max_resolution)		,dtype=np.uinta  )  )
													else:
																				A__						  =				[]
																				for i in range(self.batch_size  ):
																											A__						  =				np.random.choice(np.arange(self.min_resolution		,self.max_resolution  )		,2  )
																											image_inputs.append(np.random.randint(2_55		,size=(self.num_channels, width, height)		,dtype=np.uinta  )  )

													if not numpify and not torchify:
																				# PIL expects the channel dimension as last dimension
																				A__						  =				[Image.fromarray(np.moveaxis(__UpperCAmelCase		,0		,-1  )  ) for x in image_inputs]

													if torchify:
																				A__						  =				[torch.from_numpy(__UpperCAmelCase  ) for x in image_inputs]

													return image_inputs






@require_torch
@require_vision
class      UpperCamelCase__(      __lowerCAmelCase		,    unittest.TestCase			):
						lowerCAmelCase__	:    str    				=		BlipImageProcessor if is_vision_available() else None





						def 					snake_case__						(							self  )       ->					List[str]:
													A__						  =				BlipImageProcessingTester(self  )





						@property
						def 					snake_case__						(							self  )       ->					Optional[Any]:
													return self.image_processor_tester.prepare_image_processor_dict()





						def 					snake_case__						(							self  )       ->					Any:
													A__						  =				self.image_processing_class(**self.image_processor_dict  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'do_resize'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'size'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'do_normalize'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'image_mean'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'image_std'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'do_convert_rgb'  )  )





						def 					snake_case__						(							self  )       ->					List[str]:
													pass





						def 					snake_case__						(							self  )       ->					Optional[int]:
													A__						  =				self.image_processing_class(**self.image_processor_dict  )
													# create random PIL images
													A__						  =				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase  )
													for image in image_inputs:
																				self.assertIsInstance(__UpperCAmelCase		,Image.Image  )

													# Test not batched input
													A__						  =				image_processor(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
													A__						  =				image_processor(__UpperCAmelCase		,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 					snake_case__						(							self  )       ->					str:
													A__						  =				self.image_processing_class(**self.image_processor_dict  )
													# create random numpy tensors
													A__						  =				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase		,numpify=__UpperCAmelCase  )
													for image in image_inputs:
																				self.assertIsInstance(__UpperCAmelCase		,np.ndarray  )

													# Test not batched input
													A__						  =				image_processor(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
													A__						  =				image_processor(__UpperCAmelCase		,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 					snake_case__						(							self  )       ->					str:
													A__						  =				self.image_processing_class(**self.image_processor_dict  )
													# create random PyTorch tensors
													A__						  =				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase		,torchify=__UpperCAmelCase  )
													for image in image_inputs:
																				self.assertIsInstance(__UpperCAmelCase		,torch.Tensor  )

													# Test not batched input
													A__						  =				image_processor(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
													A__						  =				image_processor(__UpperCAmelCase		,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'],
													    )		,)






@require_torch
@require_vision
class      UpperCamelCase__(      __lowerCAmelCase		,    unittest.TestCase			):
						lowerCAmelCase__	:    Union[str, Any]    				=		BlipImageProcessor if is_vision_available() else None





						def 					snake_case__						(							self  )       ->					Optional[Any]:
													A__						  =				BlipImageProcessingTester(self		,num_channels=4  )
													A__						  =				3





						@property
						def 					snake_case__						(							self  )       ->					Dict:
													return self.image_processor_tester.prepare_image_processor_dict()





						def 					snake_case__						(							self  )       ->					Dict:
													A__						  =				self.image_processing_class(**self.image_processor_dict  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'do_resize'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'size'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'do_normalize'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'image_mean'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'image_std'  )  )
													self.assertTrue(hasattr(__UpperCAmelCase		,'do_convert_rgb'  )  )





						def 					snake_case__						(							self  )       ->					Union[str, Any]:
													pass





						def 					snake_case__						(							self  )       ->					Optional[Any]:
													A__						  =				self.image_processing_class(**self.image_processor_dict  )
													# create random PIL images
													A__						  =				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase  )
													for image in image_inputs:
																				self.assertIsInstance(__UpperCAmelCase		,Image.Image  )

													# Test not batched input
													A__						  =				image_processor(image_inputs[0]		,return_tensors='pt'  ).pixel_values
													self.assertEqual(
													    encoded_images.shape		,(
													        1,
													        self.expected_encoded_image_num_channels,
													        self.image_processor_tester.size['height'],
													        self.image_processor_tester.size['width'],
													    )		,)

													# Test batched
													A__						  =				image_processor(__UpperCAmelCase		,return_tensors='pt'  ).pixel_values
													self.assertEqual(
													    encoded_images.shape		,(
													        self.image_processor_tester.batch_size,
													        self.expected_encoded_image_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

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







def 		__a  (      _SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE  )      ->None:
  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(_SCREAMING_SNAKE_CASE  ) - 1:
    sys.exit(
        'Key A must be greater than 0 and key B must '
        F'be between 0 and {len(_SCREAMING_SNAKE_CASE  ) - 1}.'  )
  if cryptomath.gcd(_SCREAMING_SNAKE_CASE						,	len(_SCREAMING_SNAKE_CASE  )  ) != 1:
    sys.exit(
        F'Key A {key_a} and the symbol set size {len(_SCREAMING_SNAKE_CASE  )} '
        'are not relatively prime. Choose a different key.'  )







def 		__a  (      _SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE  )      ->str:
  a__				,       a__:	Optional[Any]     				=      divmod(_SCREAMING_SNAKE_CASE						,	len(_SCREAMING_SNAKE_CASE  )  )
  check_keys(_SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE						,	'encrypt'  )
  a__:	Dict     				=      ''
  for symbol in message:
    if symbol in SYMBOLS:
      a__:	int     				=      SYMBOLS.find(_SCREAMING_SNAKE_CASE  )
      cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(_SCREAMING_SNAKE_CASE  )]
    else:
      cipher_text += symbol
  return cipher_text







def 		__a  (      _SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE  )      ->str:
  a__				,       a__:	List[str]     				=      divmod(_SCREAMING_SNAKE_CASE						,	len(_SCREAMING_SNAKE_CASE  )  )
  check_keys(_SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE						,	'decrypt'  )
  a__:	List[Any]     				=      ''
  a__:	str     				=      cryptomath.find_mod_inverse(_SCREAMING_SNAKE_CASE						,	len(_SCREAMING_SNAKE_CASE  )  )
  for symbol in message:
    if symbol in SYMBOLS:
      a__:	List[str]     				=      SYMBOLS.find(_SCREAMING_SNAKE_CASE  )
      plain_text += SYMBOLS[
          (sym_index - key_b) * mod_inverse_of_key_a % len(_SCREAMING_SNAKE_CASE  )
      ]
    else:
      plain_text += symbol
  return plain_text







def 		__a  (      )      ->int:
  while True:
    a__:	int     				=      random.randint(2						,	len(_SCREAMING_SNAKE_CASE  )  )
    a__:	List[Any]     				=      random.randint(2						,	len(_SCREAMING_SNAKE_CASE  )  )
    if cryptomath.gcd(_SCREAMING_SNAKE_CASE						,	len(_SCREAMING_SNAKE_CASE  )  ) == 1 and key_b % len(_SCREAMING_SNAKE_CASE  ) != 0:
      return key_b * len(_SCREAMING_SNAKE_CASE  ) + key_b







def 		__a  (      )      ->None:
  a__:	Union[str, Any]     				=      input('Enter message: '  ).strip()
  a__:	List[Any]     				=      int(input('Enter key [2000 - 9000]: '  ).strip()  )
  a__:	List[Any]     				=      input('Encrypt/Decrypt [E/D]: '  ).strip().lower()

  if mode.startswith('e'  ):
    a__:	int     				=      'encrypt'
    a__:	List[str]     				=      encrypt_message(_SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE  )
  elif mode.startswith('d'  ):
    a__:	Dict     				=      'decrypt'
    a__:	Any     				=      decrypt_message(_SCREAMING_SNAKE_CASE						,	_SCREAMING_SNAKE_CASE  )
  print(F'\n{mode.title()}ed text: \n{translated}'  )


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 # main()


