





"""simple docstring"""






import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter



class 						lowerCAmelCase       (   TensorFormatter[Mapping, np.ndarray, Mapping]				):






       def __init__( self     ,	a__=None     ,	**a__  ):
              super().__init__(features=a__  )
              _UpperCAmelCase			     =  np_array_kwargs






       def 				__A			( self     ,	a__  ):
              if isinstance(a__     ,	a__  ):
                     if column and all(
                         isinstance(a__     ,	np.ndarray  ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column  ):
                            return np.stack(a__  )
                     else:
                            # don't use np.array(column, dtype=object)
                            # since it fails in certain cases
                            # see https://stackoverflow.com/q/51005699
                            _UpperCAmelCase			     =  np.empty(len(a__  )     ,	dtype=a__  )
                            _UpperCAmelCase			     =  column
                            return out
              return column






       def 				__A			( self     ,	a__  ):
              if isinstance(a__     ,	(str, bytes, type(a__  ))  ):
                     return value
              elif isinstance(a__     ,	(np.character, np.ndarray)  ) and np.issubdtype(value.dtype     ,	np.character  ):
                     return value
              elif isinstance(a__     ,	np.number  ):
                     return value

              _UpperCAmelCase			     =  {}

              if isinstance(a__     ,	np.ndarray  ) and np.issubdtype(value.dtype     ,	np.integer  ):
                     _UpperCAmelCase			     =  {'dtype': np.intaa}
              elif isinstance(a__     ,	np.ndarray  ) and np.issubdtype(value.dtype     ,	np.floating  ):
                     _UpperCAmelCase			     =  {'dtype': np.floataa}
              elif config.PIL_AVAILABLE and "PIL" in sys.modules:
                     import PIL.Image

                     if isinstance(a__     ,	PIL.Image.Image  ):
                            return np.asarray(a__     ,	**self.np_array_kwargs  )

              return np.asarray(a__     ,	**{**default_dtype, **self.np_array_kwargs}  )






       def 				__A			( self     ,	a__  ):
              # support for torch, tf, jax etc.
              if config.TORCH_AVAILABLE and "torch" in sys.modules:
                     import torch

                     if isinstance(a__     ,	torch.Tensor  ):
                            return self._tensorize(data_struct.detach().cpu().numpy()[()]  )
              if hasattr(a__     ,	'__array__'  ) and not isinstance(a__     ,	(np.ndarray, np.character, np.number)  ):
                     _UpperCAmelCase			     =  data_struct.__array__()
              # support for nested types like struct of list of struct
              if isinstance(a__     ,	np.ndarray  ):
                     if data_struct.dtype == object:
                            return self._consolidate([self.recursive_tensorize(a__  ) for substruct in data_struct]  )
              if isinstance(a__     ,	(list, tuple)  ):
                     return self._consolidate([self.recursive_tensorize(a__  ) for substruct in data_struct]  )
              return self._tensorize(a__  )






       def 				__A			( self     ,	a__  ):
              return map_nested(self._recursive_tensorize     ,	a__     ,	map_list=a__  )






       def 				__A			( self     ,	a__  ):
              _UpperCAmelCase			     =  self.numpy_arrow_extractor().extract_row(a__  )
              _UpperCAmelCase			     =  self.python_features_decoder.decode_row(a__  )
              return self.recursive_tensorize(a__  )






       def 				__A			( self     ,	a__  ):
              _UpperCAmelCase			     =  self.numpy_arrow_extractor().extract_column(a__  )
              _UpperCAmelCase			     =  self.python_features_decoder.decode_column(a__     ,	pa_table.column_names[0]  )
              _UpperCAmelCase			     =  self.recursive_tensorize(a__  )
              _UpperCAmelCase			     =  self._consolidate(a__  )
              return column






       def 				__A			( self     ,	a__  ):
              _UpperCAmelCase			     =  self.numpy_arrow_extractor().extract_batch(a__  )
              _UpperCAmelCase			     =  self.python_features_decoder.decode_batch(a__  )
              _UpperCAmelCase			     =  self.recursive_tensorize(a__  )
              for column_name in batch:
                     _UpperCAmelCase			     =  self._consolidate(batch[column_name]  )
              return batch









"""simple docstring"""






def 		A_	(   __UpperCamelCase     :				str       ,	__UpperCamelCase     :				str				):
		if not isinstance(__UpperCamelCase       ,	__UpperCamelCase				):
				raise TypeError('''plaintext must be a string'''				)
		if not isinstance(__UpperCamelCase       ,	__UpperCamelCase				):
				raise TypeError('''key must be a string'''				)

		if not plaintext:
				raise ValueError('''plaintext is empty'''				)
		if not key:
				raise ValueError('''key is empty'''				)

		key += plaintext
		lowercase										=							plaintext.lower()
		lowercase										=							key.lower()
		lowercase										=							0
		lowercase										=							0
		lowercase										=							''''''
		while plaintext_iterator < len(__UpperCamelCase				):
				if (
				    ord(plaintext[plaintext_iterator]				) < 97
				    or ord(plaintext[plaintext_iterator]				) > 1_22
				):
						ciphertext += plaintext[plaintext_iterator]
						plaintext_iterator += 1
				elif ord(key[key_iterator]				) < 97 or ord(key[key_iterator]				) > 1_22:
						key_iterator += 1
				else:
						ciphertext += chr(
						    (
						        (ord(plaintext[plaintext_iterator]				) - 97 + ord(key[key_iterator]				))
						        - 97
						    )
						    % 26
						    + 97				)
						key_iterator += 1
						plaintext_iterator += 1
		return ciphertext
def 		A_	(   __UpperCamelCase     :				str       ,	__UpperCamelCase     :				str				):
		if not isinstance(__UpperCamelCase       ,	__UpperCamelCase				):
				raise TypeError('''ciphertext must be a string'''				)
		if not isinstance(__UpperCamelCase       ,	__UpperCamelCase				):
				raise TypeError('''key must be a string'''				)

		if not ciphertext:
				raise ValueError('''ciphertext is empty'''				)
		if not key:
				raise ValueError('''key is empty'''				)

		lowercase										=							key.lower()
		lowercase										=							0
		lowercase										=							0
		lowercase										=							''''''
		while ciphertext_iterator < len(__UpperCamelCase				):
				if (
				    ord(ciphertext[ciphertext_iterator]				) < 97
				    or ord(ciphertext[ciphertext_iterator]				) > 1_22
				):
						plaintext += ciphertext[ciphertext_iterator]
				else:
						plaintext += chr(
						    (ord(ciphertext[ciphertext_iterator]				) - ord(key[key_iterator]				)) % 26
						    + 97				)
						key += chr(
						    (ord(ciphertext[ciphertext_iterator]				) - ord(key[key_iterator]				)) % 26
						    + 97				)
						key_iterator += 1
				ciphertext_iterator += 1
		return plaintext


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							__lowerCAmelCase				      =   int(input('''Type 1 to encrypt or 2 to decrypt:'''))
							if operation == 1:
														__lowerCAmelCase				      =   input('''Typeplaintext to be encrypted:\n''')
														__lowerCAmelCase				      =   input('''Type the key:\n''')
														print(encrypt(plaintext, key))
							elif operation == 2:
														__lowerCAmelCase				      =   input('''Type the ciphertext to be decrypted:\n''')
														__lowerCAmelCase				      =   input('''Type the key:\n''')
														print(decrypt(ciphertext, key))
							decrypt('''jsqqs avvwo''', '''coffee''')