


'''simple docstring'''







import math as m



def 						_UpperCamelCase							( UpperCamelCase__     ,   UpperCamelCase__     ,   UpperCamelCase__=0.001		):






				"""simple docstring"""



				return (f(a + h		) - f(a - h		)) / (2 * h)



def 						_UpperCamelCase							( UpperCamelCase__     ,   UpperCamelCase__=0     ,   UpperCamelCase__=100     ,   UpperCamelCase__=0.0001     ,   UpperCamelCase__=1E-6     ,   UpperCamelCase__=False		):






				"""simple docstring"""



				__magic_name__				:					Optional[int]						       =       xa  # set the initial guess
				__magic_name__				:					List[str]						       =       [a]
				__magic_name__				:					Dict						       =       abs(f(UpperCamelCase__		)		)
				__magic_name__				:					Optional[Any]						       =       lambda UpperCamelCase__		: calc_derivative(UpperCamelCase__     ,   UpperCamelCase__     ,   h=UpperCamelCase__		)  # noqa: E731  Derivative of f(x)
				for _ in range(UpperCamelCase__		):
								if fa(UpperCamelCase__		) == 0:
												raise ValueError("No converging solution found"		)
								__magic_name__				:					Any						       =       a - f(UpperCamelCase__		) / fa(UpperCamelCase__		)  # Calculate the next estimate
								if logsteps:
												steps.append(UpperCamelCase__		)
								if error < maxerror:
												break
				else:
								raise ValueError("Iteration limit reached, no converging solution found"		)
				if logsteps:
								# If logstep is true, then log intermediate steps
								return a, error, steps
				return a, error


if __name__ == "__main__":
		from matplotlib import pyplot as plt

		_SCREAMING_SNAKE_CASE       :   str        = lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
		_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE       :   List[str]        = newton_raphson(
		    f, xa=10, maxiter=10_00, step=1e-6, logsteps=True
		)
		plt.plot([abs(f(x)) for x in steps])
		plt.xlabel("step")
		plt.ylabel("error")
		plt.show()
		print(f"solution = {{{solution:f}}}, error = {{{error:f}}}")



'''simple docstring'''







def 						_UpperCamelCase							( UpperCamelCase__     ,   UpperCamelCase__		):






				"""simple docstring"""



				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		):
								raise TypeError("plaintext must be a string"		)
				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		):
								raise TypeError("key must be a string"		)

				if not plaintext:
								raise ValueError("plaintext is empty"		)
				if not key:
								raise ValueError("key is empty"		)

				key += plaintext
				__magic_name__				:					List[str]						       =       plaintext.lower()
				__magic_name__				:					Tuple						       =       key.lower()
				__magic_name__				:					Dict						       =       0
				__magic_name__				:					Optional[int]						       =       0
				__magic_name__				:					List[str]						       =       ""
				while plaintext_iterator < len(UpperCamelCase__		):
								if (
								    ord(plaintext[plaintext_iterator]		) < 97
								    or ord(plaintext[plaintext_iterator]		) > 122
								):
												ciphertext += plaintext[plaintext_iterator]
												plaintext_iterator += 1
								elif ord(key[key_iterator]		) < 97 or ord(key[key_iterator]		) > 122:
												key_iterator += 1
								else:
												ciphertext += chr(
												    (
												        (ord(plaintext[plaintext_iterator]		) - 97 + ord(key[key_iterator]		))
												        - 97
												    )
												    % 26
												    + 97		)
												key_iterator += 1
												plaintext_iterator += 1
				return ciphertext



def 						_UpperCamelCase							( UpperCamelCase__     ,   UpperCamelCase__		):






				"""simple docstring"""



				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		):
								raise TypeError("ciphertext must be a string"		)
				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		):
								raise TypeError("key must be a string"		)

				if not ciphertext:
								raise ValueError("ciphertext is empty"		)
				if not key:
								raise ValueError("key is empty"		)

				__magic_name__				:					List[str]						       =       key.lower()
				__magic_name__				:					str						       =       0
				__magic_name__				:					Optional[Any]						       =       0
				__magic_name__				:					Tuple						       =       ""
				while ciphertext_iterator < len(UpperCamelCase__		):
								if (
								    ord(ciphertext[ciphertext_iterator]		) < 97
								    or ord(ciphertext[ciphertext_iterator]		) > 122
								):
												plaintext += ciphertext[ciphertext_iterator]
								else:
												plaintext += chr(
												    (ord(ciphertext[ciphertext_iterator]		) - ord(key[key_iterator]		)) % 26
												    + 97		)
												key += chr(
												    (ord(ciphertext[ciphertext_iterator]		) - ord(key[key_iterator]		)) % 26
												    + 97		)
												key_iterator += 1
								ciphertext_iterator += 1
				return plaintext


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		_SCREAMING_SNAKE_CASE       :   Tuple        = int(input("Type 1 to encrypt or 2 to decrypt:"))
		if operation == 1:
				_SCREAMING_SNAKE_CASE       :   Optional[Any]        = input("Typeplaintext to be encrypted:\n")
				_SCREAMING_SNAKE_CASE       :   Tuple        = input("Type the key:\n")
				print(encrypt(plaintext, key))
		elif operation == 2:
				_SCREAMING_SNAKE_CASE       :   Optional[Any]        = input("Type the ciphertext to be decrypted:\n")
				_SCREAMING_SNAKE_CASE       :   List[str]        = input("Type the key:\n")
				print(decrypt(ciphertext, key))
		decrypt("jsqqs avvwo", "coffee")