






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 MobileNetVaImageProcessor


class 					_snake_case						(			unittest.TestCase ):






	def __init__(		self					,UpperCamelCase					,UpperCamelCase=7					,UpperCamelCase=3					,UpperCamelCase=18					,UpperCamelCase=30					,UpperCamelCase=400					,UpperCamelCase=True					,UpperCamelCase=None					,UpperCamelCase=True					,UpperCamelCase=None					,)						->    Optional[Any]:
					snake_case__      :Optional[Any]         =   size if size is not None else {"shortest_edge": 20}
					snake_case__      :List[str]         =   crop_size if crop_size is not None else {"height": 18, "width": 18}
					snake_case__      :Union[str, Any]         =   parent
					snake_case__      :Union[str, Any]         =   batch_size
					snake_case__      :Optional[Any]         =   num_channels
					snake_case__      :List[str]         =   image_size
					snake_case__      :List[str]         =   min_resolution
					snake_case__      :Tuple         =   max_resolution
					snake_case__      :Optional[Any]         =   do_resize
					snake_case__      :Any         =   size
					snake_case__      :Dict         =   do_center_crop
					snake_case__      :int         =   crop_size






	def    lowerCAmelCase_							(		self       )						->    Dict:
					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					}




@require_torch
@require_vision
class 					_snake_case						(			_A       ,    unittest.TestCase ):
	_A          =   MobileNetVaImageProcessor if is_vision_available() else None






	def    lowerCAmelCase_							(		self       )						->    Union[str, Any]:
					snake_case__      :List[Any]         =   MobileNetVaImageProcessingTester(self       )






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






	def    lowerCAmelCase_							(		self       )						->    Optional[Any]:
					snake_case__      :List[str]         =   self.image_processing_class(**self.image_processor_dict       )
					self.assertTrue(hasattr(UpperCamelCase					,"do_resize"       )       )
					self.assertTrue(hasattr(UpperCamelCase					,"size"       )       )
					self.assertTrue(hasattr(UpperCamelCase					,"do_center_crop"       )       )
					self.assertTrue(hasattr(UpperCamelCase					,"crop_size"       )       )






	def    lowerCAmelCase_							(		self       )						->    Dict:
					snake_case__      :List[str]         =   self.image_processing_class.from_dict(self.image_processor_dict       )
					self.assertEqual(image_processor.size					,{"shortest_edge": 20}       )
					self.assertEqual(image_processor.crop_size					,{"height": 18, "width": 18}       )

					snake_case__      :Optional[int]         =   self.image_processing_class.from_dict(self.image_processor_dict					,size=42					,crop_size=84       )
					self.assertEqual(image_processor.size					,{"shortest_edge": 42}       )
					self.assertEqual(image_processor.crop_size					,{"height": 84, "width": 84}       )






	def    lowerCAmelCase_							(		self       )						->    Optional[int]:
					pass






	def    lowerCAmelCase_							(		self       )						->    List[str]:
					# Initialize image_processing
					snake_case__      :Tuple         =   self.image_processing_class(**self.image_processor_dict       )
					# create random PIL images
					snake_case__      :int         =   prepare_image_inputs(self.image_processor_tester					,equal_resolution=UpperCamelCase       )
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase					,Image.Image       )

					# Test not batched input
					snake_case__      :Optional[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
					snake_case__      :Union[str, Any]         =   image_processing(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.crop_size["height"],
					        self.image_processor_tester.crop_size["width"],
					    )					,)






	def    lowerCAmelCase_							(		self       )						->    List[str]:
					# Initialize image_processing
					snake_case__      :Union[str, Any]         =   self.image_processing_class(**self.image_processor_dict       )
					# create random numpy tensors
					snake_case__      :Optional[Any]         =   prepare_image_inputs(self.image_processor_tester					,equal_resolution=UpperCamelCase					,numpify=UpperCamelCase       )
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase					,np.ndarray       )

					# Test not batched input
					snake_case__      :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
					snake_case__      :List[Any]         =   image_processing(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.crop_size["height"],
					        self.image_processor_tester.crop_size["width"],
					    )					,)






	def    lowerCAmelCase_							(		self       )						->    Tuple:
					# Initialize image_processing
					snake_case__      :Tuple         =   self.image_processing_class(**self.image_processor_dict       )
					# create random PyTorch tensors
					snake_case__      :Union[str, Any]         =   prepare_image_inputs(self.image_processor_tester					,equal_resolution=UpperCamelCase					,torchify=UpperCamelCase       )
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase					,torch.Tensor       )

					# Test not batched input
					snake_case__      :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
					snake_case__      :List[Any]         =   image_processing(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.crop_size["height"],
					        self.image_processor_tester.crop_size["width"],
					    )					,)







def 					lowercase_ (    __snake_case     :							Tuple	,	__snake_case     :							Optional[int]      )     -> List[Any]:





				'''simple docstring'''


				snake_case__      :Dict         =   ""
				for i in table:
								res += inp[i - 1]
				return res





def 					lowercase_ (    __snake_case     :							List[str]      )     -> int:





				'''simple docstring'''


				return data[1:] + data[0]





def 					lowercase_ (    __snake_case     :							int	,	__snake_case     :							Union[str, Any]      )     -> Union[str, Any]:





				'''simple docstring'''


				snake_case__      :Union[str, Any]         =   ""
				for i in range(len(__snake_case      )      ):
								if a[i] == b[i]:
												res += "0"
								else:
												res += "1"
				return res





def 					lowercase_ (    __snake_case     :							Optional[int]	,	__snake_case     :							Dict      )     -> Union[str, Any]:





				'''simple docstring'''


				snake_case__      :int         =   int("0b" + data[0] + data[-1]	,	2      )
				snake_case__      :Union[str, Any]         =   int("0b" + data[1:3]	,	2      )
				return bin(s[row][col]      )[2:]





def 					lowercase_ (    __snake_case     :							Dict	,	__snake_case     :							Optional[Any]	,	__snake_case     :							Dict	,	__snake_case     :							List[Any]	,	__snake_case     :							Optional[int]      )     -> List[str]:





				'''simple docstring'''


				snake_case__      :Tuple         =   message[:4]
				snake_case__      :int         =   message[4:]
				snake_case__      :int         =   apply_table(__snake_case	,	__snake_case      )
				snake_case__      :Union[str, Any]         =   xor(__snake_case	,	__snake_case      )
				snake_case__      :Tuple         =   apply_sbox(__snake_case	,	temp[:4]      )  # noqa: E741
				snake_case__      :List[str]         =   apply_sbox(__snake_case	,	temp[4:]      )
				snake_case__      :int         =   "0" * (2 - len(__snake_case      )) + l  # noqa: E741
				snake_case__      :int         =   "0" * (2 - len(__snake_case      )) + r
				snake_case__      :Optional[Any]         =   apply_table(l + r	,	__snake_case      )
				snake_case__      :Tuple         =   xor(__snake_case	,	__snake_case      )
				return temp + right


if __name__ == "__main__":
	__UpperCAmelCase							:   Dict							=  input("Enter 10 bit key: ")
	__UpperCAmelCase							:   Tuple							=  input("Enter 8 bit message: ")

	__UpperCAmelCase							:   Any							=  [6, 3, 7, 4, 8, 5, 1_0, 9]
	__UpperCAmelCase							:   List[str]							=  [3, 5, 2, 7, 4, 1_0, 1, 9, 8, 6]
	__UpperCAmelCase							:   Tuple							=  [2, 4, 3, 1]
	__UpperCAmelCase							:   List[Any]							=  [2, 6, 3, 1, 4, 8, 5, 7]
	__UpperCAmelCase							:   Optional[Any]							=  [4, 1, 3, 5, 7, 2, 8, 6]
	__UpperCAmelCase							:   Optional[int]							=  [4, 1, 2, 3, 2, 3, 4, 1]
	__UpperCAmelCase							:   List[Any]							=  [[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
	__UpperCAmelCase							:   Union[str, Any]							=  [[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

	# key generation
	__UpperCAmelCase							:   int							=  apply_table(key, paa_table)
	__UpperCAmelCase							:   Dict							=  temp[:5]
	__UpperCAmelCase							:   Optional[int]							=  temp[5:]
	__UpperCAmelCase							:   Optional[int]							=  left_shift(left)
	__UpperCAmelCase							:   Union[str, Any]							=  left_shift(right)
	__UpperCAmelCase							:   int							=  apply_table(left + right, pa_table)
	__UpperCAmelCase							:   Tuple							=  left_shift(left)
	__UpperCAmelCase							:   Union[str, Any]							=  left_shift(right)
	__UpperCAmelCase							:   Dict							=  left_shift(left)
	__UpperCAmelCase							:   Optional[Any]							=  left_shift(right)
	__UpperCAmelCase							:   Optional[int]							=  apply_table(left + right, pa_table)

	# encryption
	__UpperCAmelCase							:   Tuple							=  apply_table(message, IP)
	__UpperCAmelCase							:   Tuple							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   List[Any]							=  temp[4:] + temp[:4]
	__UpperCAmelCase							:   int							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   Union[str, Any]							=  apply_table(temp, IP_inv)
	print("Cipher text is:", CT)

	# decryption
	__UpperCAmelCase							:   List[Any]							=  apply_table(CT, IP)
	__UpperCAmelCase							:   List[Any]							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   int							=  temp[4:] + temp[:4]
	__UpperCAmelCase							:   Union[str, Any]							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   Union[str, Any]							=  apply_table(temp, IP_inv)
	print("Plain text after decypting is:", PT)