


import math





def __UpperCAmelCase       (		)						->					None:



       '''simple docstring'''





       UpperCAmelCase__										=     input("Enter message: "			)
       UpperCAmelCase__										=     int(input(F"""Enter key [2-{len(_A			) - 1}]: """			)			)
       UpperCAmelCase__										=     input("Encryption/Decryption [e/d]: "			)

       if mode.lower().startswith("e"			):
              UpperCAmelCase__										=     encrypt_message(_A ,						_A			)
       elif mode.lower().startswith("d"			):
              UpperCAmelCase__										=     decrypt_message(_A ,						_A			)

       # Append pipe symbol (vertical bar) to identify spaces at the end.
       print(F"""Output:\n{text + "|"}"""			)





def __UpperCAmelCase       (		__A ,						__A			)						->					str:



       '''simple docstring'''





       UpperCAmelCase__										=     [""] * key
       for col in range(_A			):
              UpperCAmelCase__										=     col
              while pointer < len(_A			):
                     cipher_text[col] += message[pointer]
                     pointer += key
       return "".join(_A			)





def __UpperCAmelCase       (		__A ,						__A			)						->					str:



       '''simple docstring'''





       UpperCAmelCase__										=     math.ceil(len(_A			) / key			)
       UpperCAmelCase__										=     key
       UpperCAmelCase__										=     (num_cols * num_rows) - len(_A			)
       UpperCAmelCase__										=     [""] * num_cols
       UpperCAmelCase__										=     0
       UpperCAmelCase__										=     0

       for symbol in message:
              plain_text[col] += symbol
              col += 1

              if (
                  (col == num_cols)
                  or (col == num_cols - 1)
                  and (row >= num_rows - num_shaded_boxes)
              ):
                     UpperCAmelCase__										=     0
                     row += 1

       return "".join(_A			)


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   main()









from copy import deepcopy
from typing import Optional, Union

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import TensorType, is_tf_available, is_torch_available


if is_torch_available():
    import torch

if is_tf_available():
    import tensorflow as tf


class     lowercase__  (					__SCREAMING_SNAKE_CASE		):
  A__=  ['image_processor']
  A__=  'SamImageProcessor'






  def __init__(					self      :					int		,						_lowercase      :					List[Any] ):




         """simple docstring"""







         super().__init__(_lowercase )
         UpperCAmelCase__										=     self.image_processor
         UpperCAmelCase__										=     -10
         UpperCAmelCase__										=     self.image_processor.size["longest_edge"]






  def __call__(					self      :					Union[str, Any]		,						_lowercase      :					str=None		,						_lowercase      :					Union[str, Any]=None		,						_lowercase      :					List[Any]=None		,						_lowercase      :					Dict=None		,						_lowercase      :					Optional[Union[str, TensorType]] = None		,						**_lowercase      :					Union[str, Any]		,						):




         """simple docstring"""







         UpperCAmelCase__										=     self.image_processor(
             _lowercase		,						return_tensors=_lowercase		,						**_lowercase		,						)

         # pop arguments that are not used in the foward but used nevertheless
         UpperCAmelCase__										=     encoding_image_processor["original_sizes"]

         if hasattr(_lowercase		,						"numpy" ):  # Checks if Torch or TF tensor
                UpperCAmelCase__										=     original_sizes.numpy()

         UpperCAmelCase__						,			UpperCAmelCase__						,			UpperCAmelCase__										=     self._check_and_preprocess_points(
             input_points=_lowercase		,						input_labels=_lowercase		,						input_boxes=_lowercase		,						)

         UpperCAmelCase__										=     self._normalize_and_convert(
             _lowercase		,						_lowercase		,						input_points=_lowercase		,						input_labels=_lowercase		,						input_boxes=_lowercase		,						return_tensors=_lowercase		,						)

         return encoding_image_processor






  def 			_UpperCAmelCase  (					self      :					Dict		,						_lowercase      :					int		,						_lowercase      :					Dict		,						_lowercase      :					Optional[Any]=None		,						_lowercase      :					Any=None		,						_lowercase      :					Union[str, Any]=None		,						_lowercase      :					List[Any]="pt"		,						):




         """simple docstring"""







         if input_points is not None:
                if len(_lowercase ) != len(_lowercase ):
                       UpperCAmelCase__										=     [
                           self._normalize_coordinates(self.target_size		,						_lowercase		,						original_sizes[0] ) for point in input_points
                       ]
                else:
                       UpperCAmelCase__										=     [
                           self._normalize_coordinates(self.target_size		,						_lowercase		,						_lowercase )
                           for point, original_size in zip(_lowercase		,						_lowercase )
                       ]
                # check that all arrays have the same shape
                if not all(point.shape == input_points[0].shape for point in input_points ):
                       if input_labels is not None:
                              UpperCAmelCase__						,			UpperCAmelCase__										=     self._pad_points_and_labels(_lowercase		,						_lowercase )

                UpperCAmelCase__										=     np.array(_lowercase )

         if input_labels is not None:
                UpperCAmelCase__										=     np.array(_lowercase )

         if input_boxes is not None:
                if len(_lowercase ) != len(_lowercase ):
                       UpperCAmelCase__										=     [
                           self._normalize_coordinates(self.target_size		,						_lowercase		,						original_sizes[0]		,						is_bounding_box=_lowercase )
                           for box in input_boxes
                       ]
                else:
                       UpperCAmelCase__										=     [
                           self._normalize_coordinates(self.target_size		,						_lowercase		,						_lowercase		,						is_bounding_box=_lowercase )
                           for box, original_size in zip(_lowercase		,						_lowercase )
                       ]
                UpperCAmelCase__										=     np.array(_lowercase )

         if input_boxes is not None:
                if return_tensors == "pt":
                       UpperCAmelCase__										=     torch.from_numpy(_lowercase )
                       # boxes batch size of 1 by default
                       UpperCAmelCase__										=     input_boxes.unsqueeze(1 ) if len(input_boxes.shape ) != 3 else input_boxes
                elif return_tensors == "tf":
                       UpperCAmelCase__										=     tf.convert_to_tensor(_lowercase )
                       # boxes batch size of 1 by default
                       UpperCAmelCase__										=     tf.expand_dims(_lowercase		,						1 ) if len(input_boxes.shape ) != 3 else input_boxes
                encoding_image_processor.update({"input_boxes": input_boxes} )
         if input_points is not None:
                if return_tensors == "pt":
                       UpperCAmelCase__										=     torch.from_numpy(_lowercase )
                       # point batch size of 1 by default
                       UpperCAmelCase__										=     input_points.unsqueeze(1 ) if len(input_points.shape ) != 4 else input_points
                elif return_tensors == "tf":
                       UpperCAmelCase__										=     tf.convert_to_tensor(_lowercase )
                       # point batch size of 1 by default
                       UpperCAmelCase__										=     tf.expand_dims(_lowercase		,						1 ) if len(input_points.shape ) != 4 else input_points
                encoding_image_processor.update({"input_points": input_points} )
         if input_labels is not None:
                if return_tensors == "pt":
                       UpperCAmelCase__										=     torch.from_numpy(_lowercase )
                       # point batch size of 1 by default
                       UpperCAmelCase__										=     input_labels.unsqueeze(1 ) if len(input_labels.shape ) != 3 else input_labels
                elif return_tensors == "tf":
                       UpperCAmelCase__										=     tf.convert_to_tensor(_lowercase )
                       # point batch size of 1 by default
                       UpperCAmelCase__										=     tf.expand_dims(_lowercase		,						1 ) if len(input_labels.shape ) != 3 else input_labels
                encoding_image_processor.update({"input_labels": input_labels} )

         return encoding_image_processor






  def 			_UpperCAmelCase  (					self      :					Union[str, Any]		,						_lowercase      :					Any		,						_lowercase      :					Optional[Any] ):




         """simple docstring"""







         UpperCAmelCase__										=     max([point.shape[0] for point in input_points] )
         UpperCAmelCase__										=     []
         for i, point in enumerate(_lowercase ):
                if point.shape[0] != expected_nb_points:
                       UpperCAmelCase__										=     np.concatenate(
                           [point, np.zeros((expected_nb_points - point.shape[0], 2) ) + self.point_pad_value]		,						axis=0 )
                       UpperCAmelCase__										=     np.append(input_labels[i]		,						[self.point_pad_value] )
                processed_input_points.append(_lowercase )
         UpperCAmelCase__										=     processed_input_points
         return input_points, input_labels






  def 			_UpperCAmelCase  (					self      :					Any		,						_lowercase      :					int		,						_lowercase      :					np.ndarray		,						_lowercase      :					Optional[Any]		,						_lowercase      :					Any=False ):




         """simple docstring"""







         UpperCAmelCase__						,			UpperCAmelCase__										=     original_size
         UpperCAmelCase__						,			UpperCAmelCase__										=     self.image_processor._get_preprocess_shape(_lowercase		,						longest_edge=_lowercase )
         UpperCAmelCase__										=     deepcopy(_lowercase ).astype(_lowercase )

         if is_bounding_box:
                UpperCAmelCase__										=     coords.reshape(-1		,						2		,						2 )

         UpperCAmelCase__										=     coords[..., 0] * (new_w / old_w)
         UpperCAmelCase__										=     coords[..., 1] * (new_h / old_h)

         if is_bounding_box:
                UpperCAmelCase__										=     coords.reshape(-1		,						4 )

         return coords






  def 			_UpperCAmelCase  (					self      :					int		,						_lowercase      :					Tuple=None		,						_lowercase      :					Optional[Any]=None		,						_lowercase      :					List[Any]=None		,						):




         """simple docstring"""







         if input_points is not None:
                if hasattr(_lowercase		,						"numpy" ):  # Checks for TF or Torch tensor
                       UpperCAmelCase__										=     input_points.numpy().tolist()

                if not isinstance(_lowercase		,						_lowercase ) or not isinstance(input_points[0]		,						_lowercase ):
                       raise ValueError("Input points must be a list of list of floating points." )
                UpperCAmelCase__										=     [np.array(_lowercase ) for input_point in input_points]
         else:
                UpperCAmelCase__										=     None

         if input_labels is not None:
                if hasattr(_lowercase		,						"numpy" ):
                       UpperCAmelCase__										=     input_labels.numpy().tolist()

                if not isinstance(_lowercase		,						_lowercase ) or not isinstance(input_labels[0]		,						_lowercase ):
                       raise ValueError("Input labels must be a list of list integers." )
                UpperCAmelCase__										=     [np.array(_lowercase ) for label in input_labels]
         else:
                UpperCAmelCase__										=     None

         if input_boxes is not None:
                if hasattr(_lowercase		,						"numpy" ):
                       UpperCAmelCase__										=     input_boxes.numpy().tolist()

                if (
                    not isinstance(_lowercase		,						_lowercase )
                    or not isinstance(input_boxes[0]		,						_lowercase )
                    or not isinstance(input_boxes[0][0]		,						_lowercase )
                ):
                       raise ValueError("Input boxes must be a list of list of list of floating points." )
                UpperCAmelCase__										=     [np.array(_lowercase ).astype(np.floataa ) for box in input_boxes]
         else:
                UpperCAmelCase__										=     None

         return input_points, input_labels, input_boxes






  @property
  def 			_UpperCAmelCase  (					self      :					Optional[Any] ):




         """simple docstring"""







         UpperCAmelCase__										=     self.image_processor.model_input_names
         return list(dict.fromkeys(_lowercase ) )






  def 			_UpperCAmelCase  (					self      :					int		,						*_lowercase      :					List[str]		,						**_lowercase      :					Any ):




         """simple docstring"""







         return self.image_processor.post_process_masks(*_lowercase		,						**_lowercase )





