



"""simple docstring"""
import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
      import jax.numpy as jnp

if is_tf_available():
      import tensorflow as tf

if is_torch_available():
      import torch



class       SCREAMING_SNAKE_CASE__  (					unittest.TestCase ):

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	{
        "task_specific_params": {
            "summarization": {"length_penalty": 1.0, "max_length": 128, "min_length": 12, "num_beams": 4},
            "summarization_cnn": {"length_penalty": 2.0, "max_length": 142, "min_length": 56, "num_beams": 4},
            "summarization_xsum": {"length_penalty": 1.0, "max_length": 62, "min_length": 11, "num_beams": 6},
        }
    }
    UpperCAmelCase	:					List[Any]	=	{
        "task_specific_params.summarization.length_penalty": 1.0,
        "task_specific_params.summarization.max_length": 128,
        "task_specific_params.summarization.min_length": 12,
        "task_specific_params.summarization.num_beams": 4,
        "task_specific_params.summarization_cnn.length_penalty": 2.0,
        "task_specific_params.summarization_cnn.max_length": 142,
        "task_specific_params.summarization_cnn.min_length": 56,
        "task_specific_params.summarization_cnn.num_beams": 4,
        "task_specific_params.summarization_xsum.length_penalty": 1.0,
        "task_specific_params.summarization_xsum.max_length": 62,
        "task_specific_params.summarization_xsum.min_length": 11,
        "task_specific_params.summarization_xsum.num_beams": 6,
    }

    self.assertEqual(flatten_dict(_SCREAMING_SNAKE_CASE						)      ,     _SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					Tuple	=	np.random.randn(3      ,     4						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE						)      ,     x.transpose()						)						)

    UpperCAmelCase	:					List[str]	=	np.random.randn(3      ,     4      ,     5						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						)      ,     x.transpose((1, 2, 0)						)						)						)

   @require_torch
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      str:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Optional[Any]	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE						)      ,     transpose(_SCREAMING_SNAKE_CASE						).numpy()						)						)

    UpperCAmelCase	:					Dict	=	np.random.randn(3      ,     4      ,     5						)
    UpperCAmelCase	:					Tuple	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						)      ,     transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						).numpy()						)						)

   @require_tf
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[Any]:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[int]	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Dict	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE						)      ,     transpose(_SCREAMING_SNAKE_CASE						).numpy()						)						)

    UpperCAmelCase	:					List[Any]	=	np.random.randn(3      ,     4      ,     5						)
    UpperCAmelCase	:					List[str]	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						)      ,     transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						).numpy()						)						)

   @require_flax
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Tuple:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[Any]	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Dict	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE						)      ,     np.asarray(transpose(_SCREAMING_SNAKE_CASE						)						)						)						)

    UpperCAmelCase	:					List[str]	=	np.random.randn(3      ,     4      ,     5						)
    UpperCAmelCase	:					Any	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						)      ,     np.asarray(transpose(_SCREAMING_SNAKE_CASE      ,     axes=(1, 2, 0)						)						)						)						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Dict:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[Any]	=	np.random.randn(3      ,     4						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						)      ,     np.reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						)						)						)

    UpperCAmelCase	:					Optional[Any]	=	np.random.randn(3      ,     4      ,     5						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						)      ,     np.reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						)						)						)

   @require_torch
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[Any]:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[Any]	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					str	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						)      ,     reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						).numpy()						)						)

    UpperCAmelCase	:					Any	=	np.random.randn(3      ,     4      ,     5						)
    UpperCAmelCase	:					Optional[Any]	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						)      ,     reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						).numpy()						)						)

   @require_tf
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					List[Any]	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					str	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						)      ,     reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						).numpy()						)						)

    UpperCAmelCase	:					int	=	np.random.randn(3      ,     4      ,     5						)
    UpperCAmelCase	:					Optional[int]	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						)      ,     reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						).numpy()						)						)

   @require_flax
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      str:





    '''simple docstring'''




    UpperCAmelCase	:					List[str]	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Any	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						)      ,     np.asarray(reshape(_SCREAMING_SNAKE_CASE      ,     (4, 3)						)						)						)						)

    UpperCAmelCase	:					Optional[int]	=	np.random.randn(3      ,     4      ,     5						)
    UpperCAmelCase	:					List[Any]	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						)      ,     np.asarray(reshape(_SCREAMING_SNAKE_CASE      ,     (12, 5)						)						)						)						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					List[Any]	=	np.random.randn(1      ,     3      ,     4						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE						)      ,     np.squeeze(_SCREAMING_SNAKE_CASE						)						)						)

    UpperCAmelCase	:					int	=	np.random.randn(1      ,     4      ,     1      ,     5						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						)      ,     np.squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						)						)						)

   @require_torch
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Dict:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[int]	=	np.random.randn(1      ,     3      ,     4						)
    UpperCAmelCase	:					Any	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE						)      ,     squeeze(_SCREAMING_SNAKE_CASE						).numpy()						)						)

    UpperCAmelCase	:					List[Any]	=	np.random.randn(1      ,     4      ,     1      ,     5						)
    UpperCAmelCase	:					str	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						)      ,     squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						).numpy()						)						)

   @require_tf
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Tuple:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	np.random.randn(1      ,     3      ,     4						)
    UpperCAmelCase	:					List[str]	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE						)      ,     squeeze(_SCREAMING_SNAKE_CASE						).numpy()						)						)

    UpperCAmelCase	:					Tuple	=	np.random.randn(1      ,     4      ,     1      ,     5						)
    UpperCAmelCase	:					Union[str, Any]	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						)      ,     squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						).numpy()						)						)

   @require_flax
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					int	=	np.random.randn(1      ,     3      ,     4						)
    UpperCAmelCase	:					Tuple	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE						)      ,     np.asarray(squeeze(_SCREAMING_SNAKE_CASE						)						)						)						)

    UpperCAmelCase	:					int	=	np.random.randn(1      ,     4      ,     1      ,     5						)
    UpperCAmelCase	:					Optional[Any]	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						)      ,     np.asarray(squeeze(_SCREAMING_SNAKE_CASE      ,     axis=2						)						)						)						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					Tuple	=	np.random.randn(3      ,     4						)
    self.assertTrue(np.allclose(expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						)      ,     np.expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						)						)						)

   @require_torch
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[int]:





    '''simple docstring'''




    UpperCAmelCase	:					Any	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Dict	=	torch.tensor(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						)      ,     expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						).numpy()						)						)

   @require_tf
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[Any]:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Dict	=	tf.constant(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						)      ,     expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						).numpy()						)						)




   @require_flax
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					Any	=	np.random.randn(3      ,     4						)
    UpperCAmelCase	:					Optional[int]	=	jnp.array(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(np.allclose(expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						)      ,     np.asarray(expand_dims(_SCREAMING_SNAKE_CASE      ,     axis=1						)						)						)						)


import math




def 	_SCREAMING_SNAKE_CASE					(		)					->    None:






							'''simple docstring'''





							__UpperCamelCase	:   List[Any]			   =					input("Enter message: ")
							__UpperCamelCase	:   Optional[int]			   =					int(input(F'Enter key [2-{len(_lowerCamelCase) - 1}]: '))
							__UpperCamelCase	:   str			   =					input("Encryption/Decryption [e/d]: ")

							if mode.lower().startswith("e"):
														__UpperCamelCase	:   List[str]			   =					encrypt_message(_lowerCamelCase						,  _lowerCamelCase)
							elif mode.lower().startswith("d"):
														__UpperCamelCase	:   Dict			   =					decrypt_message(_lowerCamelCase						,  _lowerCamelCase)

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




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			int						,  _lowerCamelCase :			str)					->    str:






							'''simple docstring'''





							__UpperCamelCase	:   Optional[Any]			   =					[""] * key
							for col in range(_lowerCamelCase):
														__UpperCamelCase	:   Any			   =					col
														while pointer < len(_lowerCamelCase):
																					cipher_text[col] += message[pointer]
																					pointer += key
							return "".join(_lowerCamelCase)




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			int						,  _lowerCamelCase :			str)					->    str:






							'''simple docstring'''





							__UpperCamelCase	:   Any			   =					math.ceil(len(_lowerCamelCase) / key)
							__UpperCamelCase	:   Any			   =					key
							__UpperCamelCase	:   str			   =					(num_cols * num_rows) - len(_lowerCamelCase)
							__UpperCamelCase	:   Union[str, Any]			   =					[""] * num_cols
							__UpperCamelCase	:   Dict			   =					0
							__UpperCamelCase	:   int			   =					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	:   List[Any]			   =					0
																					row += 1

							return "".join(_lowerCamelCase)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		main()