






import os
import string
import sys


__UpperCAmelCase							:   List[str]							=  1 << 8

__UpperCAmelCase							:   List[Any]							=  {
    "tab": ord("\t"),
    "newline": ord("\r"),
    "esc": 2_7,
    "up": 6_5 + ARROW_KEY_FLAG,
    "down": 6_6 + ARROW_KEY_FLAG,
    "right": 6_7 + ARROW_KEY_FLAG,
    "left": 6_8 + ARROW_KEY_FLAG,
    "mod_int": 9_1,
    "undefined": sys.maxsize,
    "interrupt": 3,
    "insert": 5_0,
    "delete": 5_1,
    "pg_up": 5_3,
    "pg_down": 5_4,
}

__UpperCAmelCase							:   List[str]							=  KEYMAP["up"]
__UpperCAmelCase							:   List[str]							=  KEYMAP["left"]

if sys.platform == "win32":
	__UpperCAmelCase							:   int							=  []
	__UpperCAmelCase							:   List[str]							=  {
	    B"\xe0H": KEYMAP["up"] - ARROW_KEY_FLAG,
	    B"\x00H": KEYMAP["up"] - ARROW_KEY_FLAG,
	    B"\xe0P": KEYMAP["down"] - ARROW_KEY_FLAG,
	    B"\x00P": KEYMAP["down"] - ARROW_KEY_FLAG,
	    B"\xe0M": KEYMAP["right"] - ARROW_KEY_FLAG,
	    B"\x00M": KEYMAP["right"] - ARROW_KEY_FLAG,
	    B"\xe0K": KEYMAP["left"] - ARROW_KEY_FLAG,
	    B"\x00K": KEYMAP["left"] - ARROW_KEY_FLAG,
	}

for i in range(1_0):
	__UpperCAmelCase							:   int							=  ord(str(i))





def 					lowercase_ (    )     -> List[Any]:





				'''simple docstring'''


				if os.name == "nt":
								import msvcrt

								snake_case__      :List[Any]         =   "mbcs"
								# Flush the keyboard buffer
								while msvcrt.kbhit():
												msvcrt.getch()
								if len(_UpperCamelCase      ) == 0:
												# Read the keystroke
												snake_case__      :Dict         =   msvcrt.getch()

												# If it is a prefix char, get second part
												if ch in (b"\x00", b"\xe0"):
																snake_case__      :Tuple         =   ch + msvcrt.getch()
																# Translate actual Win chars to bullet char types
																try:
																				snake_case__      :Dict         =   chr(WIN_KEYMAP[cha]      )
																				WIN_CH_BUFFER.append(chr(KEYMAP["mod_int"]      )      )
																				WIN_CH_BUFFER.append(_UpperCamelCase      )
																				if ord(_UpperCamelCase      ) in (
																				    KEYMAP["insert"] - 1 << 9,
																				    KEYMAP["delete"] - 1 << 9,
																				    KEYMAP["pg_up"] - 1 << 9,
																				    KEYMAP["pg_down"] - 1 << 9,
																				):
																								WIN_CH_BUFFER.append(chr(1_26      )      )
																				snake_case__      :str         =   chr(KEYMAP["esc"]      )
																except KeyError:
																				snake_case__      :int         =   cha[1]
												else:
																snake_case__      :List[str]         =   ch.decode(_UpperCamelCase      )
								else:
												snake_case__      :Union[str, Any]         =   WIN_CH_BUFFER.pop(0      )
				elif os.name == "posix":
								import termios
								import tty

								snake_case__      :str         =   sys.stdin.fileno()
								snake_case__      :Union[str, Any]         =   termios.tcgetattr(_UpperCamelCase      )
								try:
												tty.setraw(_UpperCamelCase      )
												snake_case__      :Union[str, Any]         =   sys.stdin.read(1      )
								finally:
												termios.tcsetattr(_UpperCamelCase	,	termios.TCSADRAIN	,	_UpperCamelCase      )
				return ch





def 					lowercase_ (    )     -> Union[str, Any]:





				'''simple docstring'''


				snake_case__      :str         =   get_raw_chars()
				if ord(_UpperCamelCase      ) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
								return char

				elif ord(_UpperCamelCase      ) == KEYMAP["esc"]:
								snake_case__      :int         =   get_raw_chars()
								if ord(_UpperCamelCase      ) == KEYMAP["mod_int"]:
												snake_case__      :Union[str, Any]         =   get_raw_chars()
												if ord(_UpperCamelCase      ) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(_UpperCamelCase      ) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
																return chr(ord(_UpperCamelCase      ) + ARROW_KEY_FLAG      )
												else:
																return KEYMAP["undefined"]
								else:
												return get_raw_chars()

				else:
								if char in string.printable:
												return char
								else:
												return KEYMAP["undefined"]







def 					lowercase_ (    __snake_case     :							Tuple	,	__snake_case     :							Optional[int]      )     -> List[Any]:





				'''simple docstring'''


				snake_case__      :Dict         =   ""
				for i in table:
								res += inp[i - 1]
				return res





def 					lowercase_ (    __snake_case     :							List[str]      )     -> int:





				'''simple docstring'''


				return data[1:] + data[0]





def 					lowercase_ (    __snake_case     :							int	,	__snake_case     :							Union[str, Any]      )     -> Union[str, Any]:





				'''simple docstring'''


				snake_case__      :Union[str, Any]         =   ""
				for i in range(len(__snake_case      )      ):
								if a[i] == b[i]:
												res += "0"
								else:
												res += "1"
				return res





def 					lowercase_ (    __snake_case     :							Optional[int]	,	__snake_case     :							Dict      )     -> Union[str, Any]:





				'''simple docstring'''


				snake_case__      :int         =   int("0b" + data[0] + data[-1]	,	2      )
				snake_case__      :Union[str, Any]         =   int("0b" + data[1:3]	,	2      )
				return bin(s[row][col]      )[2:]





def 					lowercase_ (    __snake_case     :							Dict	,	__snake_case     :							Optional[Any]	,	__snake_case     :							Dict	,	__snake_case     :							List[Any]	,	__snake_case     :							Optional[int]      )     -> List[str]:





				'''simple docstring'''


				snake_case__      :Tuple         =   message[:4]
				snake_case__      :int         =   message[4:]
				snake_case__      :int         =   apply_table(__snake_case	,	__snake_case      )
				snake_case__      :Union[str, Any]         =   xor(__snake_case	,	__snake_case      )
				snake_case__      :Tuple         =   apply_sbox(__snake_case	,	temp[:4]      )  # noqa: E741
				snake_case__      :List[str]         =   apply_sbox(__snake_case	,	temp[4:]      )
				snake_case__      :int         =   "0" * (2 - len(__snake_case      )) + l  # noqa: E741
				snake_case__      :int         =   "0" * (2 - len(__snake_case      )) + r
				snake_case__      :Optional[Any]         =   apply_table(l + r	,	__snake_case      )
				snake_case__      :Tuple         =   xor(__snake_case	,	__snake_case      )
				return temp + right


if __name__ == "__main__":
	__UpperCAmelCase							:   Dict							=  input("Enter 10 bit key: ")
	__UpperCAmelCase							:   Tuple							=  input("Enter 8 bit message: ")

	__UpperCAmelCase							:   Any							=  [6, 3, 7, 4, 8, 5, 1_0, 9]
	__UpperCAmelCase							:   List[str]							=  [3, 5, 2, 7, 4, 1_0, 1, 9, 8, 6]
	__UpperCAmelCase							:   Tuple							=  [2, 4, 3, 1]
	__UpperCAmelCase							:   List[Any]							=  [2, 6, 3, 1, 4, 8, 5, 7]
	__UpperCAmelCase							:   Optional[Any]							=  [4, 1, 3, 5, 7, 2, 8, 6]
	__UpperCAmelCase							:   Optional[int]							=  [4, 1, 2, 3, 2, 3, 4, 1]
	__UpperCAmelCase							:   List[Any]							=  [[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
	__UpperCAmelCase							:   Union[str, Any]							=  [[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

	# key generation
	__UpperCAmelCase							:   int							=  apply_table(key, paa_table)
	__UpperCAmelCase							:   Dict							=  temp[:5]
	__UpperCAmelCase							:   Optional[int]							=  temp[5:]
	__UpperCAmelCase							:   Optional[int]							=  left_shift(left)
	__UpperCAmelCase							:   Union[str, Any]							=  left_shift(right)
	__UpperCAmelCase							:   int							=  apply_table(left + right, pa_table)
	__UpperCAmelCase							:   Tuple							=  left_shift(left)
	__UpperCAmelCase							:   Union[str, Any]							=  left_shift(right)
	__UpperCAmelCase							:   Dict							=  left_shift(left)
	__UpperCAmelCase							:   Optional[Any]							=  left_shift(right)
	__UpperCAmelCase							:   Optional[int]							=  apply_table(left + right, pa_table)

	# encryption
	__UpperCAmelCase							:   Tuple							=  apply_table(message, IP)
	__UpperCAmelCase							:   Tuple							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   List[Any]							=  temp[4:] + temp[:4]
	__UpperCAmelCase							:   int							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   Union[str, Any]							=  apply_table(temp, IP_inv)
	print("Cipher text is:", CT)

	# decryption
	__UpperCAmelCase							:   List[Any]							=  apply_table(CT, IP)
	__UpperCAmelCase							:   List[Any]							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   int							=  temp[4:] + temp[:4]
	__UpperCAmelCase							:   Union[str, Any]							=  function(expansion, sa, sa, keya, temp)
	__UpperCAmelCase							:   Union[str, Any]							=  apply_table(temp, IP_inv)
	print("Plain text after decypting is:", PT)