

'''simple docstring'''

import random
import sys

lowercase__            =     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"




def  UpperCamelCase(	):
 UpperCAmelCase			:      List[str]		   =					input('Enter message: '      )
 UpperCAmelCase			:      Optional[Any]		   =					'LFWOAYUISVKMNXPBDCRJTQEGHZ'
 UpperCAmelCase			:      str		   =					input('Encrypt/Decrypt [e/d]: '      )

 check_valid_key(UpperCAmelCase_      )

 if resp.lower().startswith('e'      ):
  UpperCAmelCase			:      List[str]		   =					'encrypt'
  UpperCAmelCase			:      str		   =					encrypt_message(UpperCAmelCase_    ,			UpperCAmelCase_      )
 elif resp.lower().startswith('d'      ):
  UpperCAmelCase			:      Union[str, Any]		   =					'decrypt'
  UpperCAmelCase			:      List[str]		   =					decrypt_message(UpperCAmelCase_    ,			UpperCAmelCase_      )

 print(F"""\n{mode.title()}ion: \n{translated}"""      )




def  UpperCamelCase(	UpperCAmelCase_      ):
 UpperCAmelCase			:      str		   =					list(UpperCAmelCase_      )
 UpperCAmelCase			:      Optional[Any]		   =					list(UpperCAmelCase_      )
 key_list.sort()
 letters_list.sort()

 if key_list != letters_list:
  sys.exit('Error in the key or symbol set.'      )




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_      ):
 return translate_message(UpperCAmelCase_    ,			UpperCAmelCase_    ,			'encrypt'      )




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_      ):
 return translate_message(UpperCAmelCase_    ,			UpperCAmelCase_    ,			'decrypt'      )




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_    ,			UpperCAmelCase_      ):
 UpperCAmelCase			:      Optional[Any]		   =					''
 UpperCAmelCase			:      Tuple		   =					LETTERS
 UpperCAmelCase			:      Optional[int]		   =					key

 if mode == "decrypt":
  UpperCAmelCase   ,					UpperCAmelCase			:      Dict		   =					chars_b, chars_a

 for symbol in message:
  if symbol.upper() in chars_a:
   UpperCAmelCase			:      Optional[int]		   =					chars_a.find(symbol.upper()      )
   if symbol.isupper():
    translated += chars_b[sym_index].upper()
   else:
    translated += chars_b[sym_index].lower()
  else:
   translated += symbol

 return translated




def  UpperCamelCase(	):
 UpperCAmelCase			:      List[Any]		   =					list(UpperCAmelCase_      )
 random.shuffle(UpperCAmelCase_      )
 return "".join(UpperCAmelCase_      )


if __name__ == "__main__":
 main()







'''simple docstring'''

from __future__ import annotations




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_    ,			UpperCAmelCase_      ):
 assert n > 1 and a > 0 and greatest_common_divisor(UpperCAmelCase_    ,			UpperCAmelCase_      ) == 1
 ((UpperCAmelCase)   ,					(UpperCAmelCase)   ,					(UpperCAmelCase))			:      Dict		   =					extended_gcd(UpperCAmelCase_    ,			UpperCAmelCase_      )  # Implemented below
 UpperCAmelCase			:      int		   =					(b * s) % n
 return x




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_      ):
 ((UpperCAmelCase)   ,					(UpperCAmelCase))			:      int		   =					extended_euclid(UpperCAmelCase_    ,			UpperCAmelCase_      )  # Implemented below
 if b < 0:
  UpperCAmelCase			:      Optional[int]		   =					(b % n + n) % n
 return b




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_    ,			UpperCAmelCase_      ):
 UpperCAmelCase			:      Tuple		   =					invert_modulo(UpperCAmelCase_    ,			UpperCAmelCase_      )
 UpperCAmelCase			:      List[Any]		   =					(b * s) % n
 return x




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_      ):
 assert a >= 0 and b >= 0

 if b == 0:
  UpperCAmelCase   ,					UpperCAmelCase   ,					UpperCAmelCase			:      Dict		   =					a, 1, 0
 else:
  ((UpperCAmelCase)   ,					(UpperCAmelCase)   ,					(UpperCAmelCase))			:      Optional[int]		   =					extended_gcd(UpperCAmelCase_    ,			a % b      )
  UpperCAmelCase			:      Dict		   =					q
  UpperCAmelCase			:      int		   =					p - q * (a // b)

 assert a % d == 0 and b % d == 0
 assert d == a * x + b * y

 return (d, x, y)




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_      ):
 if b == 0:
  return (1, 0)
 ((UpperCAmelCase)   ,					(UpperCAmelCase))			:      Tuple		   =					extended_euclid(UpperCAmelCase_    ,			a % b      )
 UpperCAmelCase			:      Tuple		   =					a // b
 return (y, x - k * y)




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_      ):
 if a < b:
  UpperCAmelCase   ,					UpperCAmelCase			:      Union[str, Any]		   =					b, a

 while a % b != 0:
  UpperCAmelCase   ,					UpperCAmelCase			:      int		   =					b, a % b

 return b


if __name__ == "__main__":
 from doctest import testmod

 testmod(name="modular_division", verbose=True)
 testmod(name="modular_division2", verbose=True)
 testmod(name="invert_modulo", verbose=True)
 testmod(name="extended_gcd", verbose=True)
 testmod(name="extended_euclid", verbose=True)
 testmod(name="greatest_common_divisor", verbose=True)




