



'''simple docstring'''






from __future__ import annotations


def 			snake_case_					( _lowerCAmelCase  :						str       ,				_lowerCAmelCase  :						dict[str, str]  )				->       str:
							UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase			:	Tuple										=		'''''', '''''', ''''''
							UpperCAmelCase			:	Tuple										=		[]

							for character in message_part:
														tmp.append(character_to_number[character]  )

							for each in tmp:
														one += each[0]
														two += each[1]
														three += each[2]

							return one + two + three


def 			snake_case_					( _lowerCAmelCase  :						str       ,				_lowerCAmelCase  :						dict[str, str]  )				->       tuple[str, str, str]:
							UpperCAmelCase							,		UpperCAmelCase			:	Union[str, Any]										=		'''''', ''''''
							UpperCAmelCase			:	Tuple										=		[]

							for character in message_part:
														this_part += character_to_number[character]

							for digit in this_part:
														tmp += digit
														if len(_lowerCAmelCase  ) == len(_lowerCAmelCase  ):
																					result.append(_lowerCAmelCase  )
																					UpperCAmelCase			:	List[Any]										=		''''''

							return result[0], result[1], result[2]


def 			snake_case_					( _lowerCAmelCase  :						str       ,				_lowerCAmelCase  :						str  )				->       tuple[str, str, dict[str, str], dict[str, str]]:
							# Validate message and alphabet, set to upper and remove spaces
							UpperCAmelCase			:	List[Any]										=		alphabet.replace(''' '''       ,				''''''  ).upper()
							UpperCAmelCase			:	Optional[int]										=		message.replace(''' '''       ,				''''''  ).upper()

							# Check length and characters
							if len(_lowerCAmelCase  ) != 27:
														raise KeyError('''Length of alphabet has to be 27.'''  )
							for each in message:
														if each not in alphabet:
																					raise ValueError('''Each message character has to be included in alphabet!'''  )

    # Generate dictionares
							UpperCAmelCase			:	int										=		(
							    '''111''',
							    '''112''',
							    '''113''',
							    '''121''',
							    '''122''',
							    '''123''',
							    '''131''',
							    '''132''',
							    '''133''',
							    '''211''',
							    '''212''',
							    '''213''',
							    '''221''',
							    '''222''',
							    '''223''',
							    '''231''',
							    '''232''',
							    '''233''',
							    '''311''',
							    '''312''',
							    '''313''',
							    '''321''',
							    '''322''',
							    '''323''',
							    '''331''',
							    '''332''',
							    '''333''',
							)
							UpperCAmelCase			:	Optional[int]										=		{}
							UpperCAmelCase			:	List[str]										=		{}
							for letter, number in zip(_lowerCAmelCase       ,				_lowerCAmelCase  ):
														UpperCAmelCase			:	List[Any]										=		number
														UpperCAmelCase			:	int										=		letter

							return message, alphabet, character_to_number, number_to_character


def 			snake_case_					( _lowerCAmelCase  :						str       ,				_lowerCAmelCase  :						str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."       ,				_lowerCAmelCase  :						int = 5  )				->       str:
							UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase			:	Optional[int]										=		__prepare(
							    _lowerCAmelCase       ,				_lowerCAmelCase  )
							UpperCAmelCase							,		UpperCAmelCase			:	List[Any]										=		'''''', ''''''

							for i in range(0       ,				len(_lowerCAmelCase  ) + 1       ,				_lowerCAmelCase  ):
														encrypted_numeric += __encrypt_part(
														    message[i : i + period]       ,				_lowerCAmelCase  )

							for i in range(0       ,				len(_lowerCAmelCase  )       ,				3  ):
														encrypted += number_to_character[encrypted_numeric[i : i + 3]]

							return encrypted


def 			snake_case_					( _lowerCAmelCase  :						str       ,				_lowerCAmelCase  :						str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."       ,				_lowerCAmelCase  :						int = 5  )				->       str:
							UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase			:	List[Any]										=		__prepare(
							    _lowerCAmelCase       ,				_lowerCAmelCase  )
							UpperCAmelCase			:	int										=		[]
							UpperCAmelCase			:	List[Any]										=		''''''

							for i in range(0       ,				len(_lowerCAmelCase  ) + 1       ,				_lowerCAmelCase  ):
														UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase			:	int										=		__decrypt_part(message[i : i + period]       ,				_lowerCAmelCase  )

														for j in range(0       ,				len(_lowerCAmelCase  )  ):
																					decrypted_numeric.append(a[j] + b[j] + c[j]  )

							for each in decrypted_numeric:
														decrypted += number_to_character[each]

							return decrypted


if __name__ == "__main__":
						UpperCamelCase__:       Any							     =      "DEFEND THE EAST WALL OF THE CASTLE."
						UpperCamelCase__:       Optional[Any]							     =      encrypt_message(msg, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
						UpperCamelCase__:       Union[str, Any]							     =      decrypt_message(encrypted, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
						print(F"Encrypted: {encrypted}\nDecrypted: {decrypted}")










'''simple docstring'''






import importlib.metadata
import subprocess
import sys


def 			snake_case_					( _lowerCAmelCase  :						bool = False  )				->       str:
							UpperCAmelCase			:	List[str]										=		False
							if "IPython" in sys.modules:
														UpperCAmelCase			:	Optional[Any]										=		'''google.colab''' in str(sys.modules['''IPython'''].get_ipython()  )

							if in_colab:
														if upgrade:
																					UpperCAmelCase			:	List[Any]										=		['''pip''', '''install''', '''-U''', '''torch''']
																					subprocess.run(_lowerCAmelCase       ,				check=_lowerCAmelCase  )
														# get the current version of torch
														UpperCAmelCase			:	Dict										=		importlib.metadata.version('''torch'''  )
														UpperCAmelCase			:	int										=		torch_version[: torch_version.rindex('''.'''  )]
														UpperCAmelCase			:	Any										=		f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
														UpperCAmelCase			:	List[str]										=		['''pip''', '''install''', xla_wheel]
														subprocess.run(_lowerCAmelCase       ,				check=_lowerCAmelCase  )
							else:
														raise RuntimeError('''`install_xla` utility works only on google colab.'''  )





