



'''simple docstring'''

import os
import string
import sys


UpperCAmelCase     		=   1 << 8

UpperCAmelCase     		=   {
    'tab': ord('\t'),
    'newline': ord('\r'),
    'esc': 27,
    'up': 65 + ARROW_KEY_FLAG,
    'down': 66 + ARROW_KEY_FLAG,
    'right': 67 + ARROW_KEY_FLAG,
    'left': 68 + ARROW_KEY_FLAG,
    'mod_int': 91,
    'undefined': sys.maxsize,
    'interrupt': 3,
    'insert': 50,
    'delete': 51,
    'pg_up': 53,
    'pg_down': 54,
}

UpperCAmelCase     		=   KEYMAP['up']
UpperCAmelCase     		=   KEYMAP['left']

if sys.platform == "win32":
				UpperCAmelCase     		=   []
				UpperCAmelCase     		=   {
				    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(10):
				UpperCAmelCase     		=   ord(str(i))






def 		_snake_case		( )      ->						Dict:







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

		lowerCAmelCase   =     """mbcs"""
		# Flush the keyboard buffer
		while msvcrt.kbhit():
			msvcrt.getch()
		if len(__lowerCamelCase							) == 0:
			# Read the keystroke
			lowerCAmelCase   =     msvcrt.getch()

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

		lowerCAmelCase   =     sys.stdin.fileno()
		lowerCAmelCase   =     termios.tcgetattr(__lowerCamelCase							)
		try:
			tty.setraw(__lowerCamelCase							)
			lowerCAmelCase   =     sys.stdin.read(1							)
		finally:
			termios.tcsetattr(__lowerCamelCase							,		termios.TCSADRAIN							,		__lowerCamelCase							)
	return ch






def 		_snake_case		( )      ->						str:







	"""simple docstring"""
	lowerCAmelCase   =     get_raw_chars()
	if ord(__lowerCamelCase							) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
		return char

	elif ord(__lowerCamelCase							) == KEYMAP["esc"]:
		lowerCAmelCase   =     get_raw_chars()
		if ord(__lowerCamelCase							) == KEYMAP["mod_int"]:
			lowerCAmelCase   =     get_raw_chars()
			if ord(__lowerCamelCase							) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(__lowerCamelCase							) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
				return chr(ord(__lowerCamelCase							) + ARROW_KEY_FLAG							)
			else:
				return KEYMAP["undefined"]
		else:
			return get_raw_chars()

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




'''simple docstring'''

from __future__ import annotations

class __snake_case:


						'''simple docstring'''



						def __init__( self     ,	A_ = 0				)     ->     Dict:
							lowerCAmelCase   =     key


						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     list[str]:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key is an appropriate size
							key %= 255

							return [chr(ord(A_				) ^ key				) for ch in content]


						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     list[str]:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key is an appropriate size
							key %= 255

							return [chr(ord(A_				) ^ key				) for ch in content]


						def     __snake_case   ( self     ,	A_     ,	A_ = 0				)     ->     str:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key can be any size
							while key > 255:
								key -= 255

							# This will be returned
							lowerCAmelCase   =     """"""

							for ch in content:
								ans += chr(ord(A_				) ^ key				)

							return ans


						def     __snake_case   ( self     ,	A_     ,	A_ = 0				)     ->     str:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key can be any size
							while key > 255:
								key -= 255

							# This will be returned
							lowerCAmelCase   =     """"""

							for ch in content:
								ans += chr(ord(A_				) ^ key				)

							return ans


						def     __snake_case   ( self     ,	A_     ,	A_ = 0				)     ->     bool:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							try:
								with open(A_				) as fin, open("""encrypt.out"""     ,	"""w+"""				) as fout:
									# actual encrypt-process
									for line in fin:
										fout.write(self.encrypt_string(A_     ,	A_				)				)

							except OSError:
								return False

							return True




						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     bool:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							try:
								with open(A_				) as fin, open("""decrypt.out"""     ,	"""w+"""				) as fout:
									# actual encrypt-process
									for line in fin:
										fout.write(self.decrypt_string(A_     ,	A_				)				)

							except OSError:
								return False

							return True


# Tests
# crypt = XORCipher()
# key = 67

# # test encrypt
# print(crypt.encrypt("hallo welt",key))
# # test decrypt
# print(crypt.decrypt(crypt.encrypt("hallo welt",key), key))

# # test encrypt_string
# print(crypt.encrypt_string("hallo welt",key))

# # test decrypt_string
# print(crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key))

# if (crypt.encrypt_file("test.txt",key)):
#       print("encrypt successful")
# else:
#       print("encrypt unsuccessful")

# if (crypt.decrypt_file("encrypt.out",key)):
#       print("decrypt successful")
# else:
#       print("decrypt unsuccessful")