



"""simple docstring"""






class 	__lowerCAmelCase							:


					'''simple docstring'''


					def __init__(      self    ,       a   ):




										"""simple docstring"""





										snake_case_						:Dict								=						data
										snake_case_						:Any								=						None
										snake_case_						:str								=						None







					def __str__(      self   ):




										"""simple docstring"""





										return F'''{self.data}'''



class 	__lowerCAmelCase							:


					'''simple docstring'''


					def __init__(      self   ):




										"""simple docstring"""





										snake_case_						:Optional[Any]								=						None
										snake_case_						:Union[str, Any]								=						None







					def __iter__(      self   ):




										"""simple docstring"""





										snake_case_						:List[str]								=						self.head
										while node:
															yield node.data
															snake_case_						:int								=						node.next







					def __str__(      self   ):




										"""simple docstring"""





										return "->".join([str(lowerCamelCase_   ) for item in self]   )







					def __len__(      self   ):




										"""simple docstring"""





										return sum(1 for _ in self   )







					def 		_a (      self    ,       a   ):




										"""simple docstring"""





										self.insert_at_nth(0    ,       lowerCamelCase_   )







					def 		_a (      self    ,       a   ):




										"""simple docstring"""





										self.insert_at_nth(len(self   )    ,       lowerCamelCase_   )







					def 		_a (      self    ,       a    ,       a   ):




										"""simple docstring"""





										snake_case_						:Optional[int]								=						len(self   )

										if not 0 <= index <= length:
															raise IndexError("list index out of range"   )
										snake_case_						:Optional[Any]								=						Node(lowerCamelCase_   )
										if self.head is None:
															snake_case_						:Optional[Any]								=						new_node
										elif index == 0:
															snake_case_						:List[Any]								=						new_node
															snake_case_						:Optional[int]								=						self.head
															snake_case_						:Union[str, Any]								=						new_node
										elif index == length:
															snake_case_						:Tuple								=						new_node
															snake_case_						:Tuple								=						self.tail
															snake_case_						:Union[str, Any]								=						new_node
										else:
															snake_case_						:Optional[int]								=						self.head
															for _ in range(0    ,       lowerCamelCase_   ):
																				snake_case_						:Optional[int]								=						temp.next
															snake_case_						:Tuple								=						new_node
															snake_case_						:Any								=						temp.previous
															snake_case_						:int								=						temp
															snake_case_						:Tuple								=						new_node







					def 		_a (      self   ):




										"""simple docstring"""





										return self.delete_at_nth(0   )







					def 		_a (      self   ):




										"""simple docstring"""





										return self.delete_at_nth(len(self   ) - 1   )







					def 		_a (      self    ,       a   ):




										"""simple docstring"""





										snake_case_						:Union[str, Any]								=						len(self   )

										if not 0 <= index <= length - 1:
															raise IndexError("list index out of range"   )
										snake_case_						:Union[str, Any]								=						self.head  # default first node
										if length == 1:
															snake_case_						:List[str]								=						None
										elif index == 0:
															snake_case_						:Optional[Any]								=						self.head.next
															snake_case_						:Optional[int]								=						None
										elif index == length - 1:
															snake_case_						:Union[str, Any]								=						self.tail
															snake_case_						:Optional[Any]								=						self.tail.previous
															snake_case_						:Union[str, Any]								=						None
										else:
															snake_case_						:Dict								=						self.head
															for _ in range(0    ,       lowerCamelCase_   ):
																				snake_case_						:List[str]								=						temp.next
															snake_case_						:List[Any]								=						temp
															snake_case_						:Union[str, Any]								=						temp.previous
															snake_case_						:List[Any]								=						temp.next
										return delete_node.data







					def 		_a (      self    ,       a   ):




										"""simple docstring"""





										snake_case_						:Optional[Any]								=						self.head

										while current.data != data:  # Find the position to delete
															if current.next:
																				snake_case_						:List[Any]								=						current.next
															else:  # We have reached the end an no value matches
																				raise ValueError("No data matching given value"   )

										if current == self.head:
															self.delete_head()

										elif current == self.tail:
															self.delete_tail()

										else:  # Before: 1 <--> 2(current) <--> 3
															snake_case_						:str								=						current.next  # 1 --> 3
															snake_case_						:Optional[int]								=						current.previous  # 1 <--> 3
										return data







					def 		_a (      self   ):




										"""simple docstring"""





										return len(self   ) == 0



def      A      (			):




					"""simple docstring"""
					snake_case_						:Optional[int]								=						DoublyLinkedList()
					assert linked_list.is_empty() is True
					assert str(a_							) == ""

					try:
										linked_list.delete_head()
										raise AssertionError  # This should not happen.
					except IndexError:
										assert True  # This should happen.

					try:
										linked_list.delete_tail()
										raise AssertionError  # This should not happen.
					except IndexError:
										assert True  # This should happen.

					for i in range(10							):
										assert len(a_							) == i
										linked_list.insert_at_nth(a_,     i + 1							)
					assert str(a_							) == "->".join(str(a_							) for i in range(1,     11							)							)

					linked_list.insert_at_head(0							)
					linked_list.insert_at_tail(11							)
					assert str(a_							) == "->".join(str(a_							) for i in range(0,     12							)							)

					assert linked_list.delete_head() == 0
					assert linked_list.delete_at_nth(9							) == 10
					assert linked_list.delete_tail() == 11
					assert len(a_							) == 9
					assert str(a_							) == "->".join(str(a_							) for i in range(1,     10							)							)


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

				testmod()










"""simple docstring"""






def      A      (			_A,     _A							):




					"""simple docstring"""
					if not isinstance(_A,     _A							):
										raise TypeError("plaintext must be a string"							)
					if not isinstance(_A,     _A							):
										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
					snake_case_						:Optional[int]								=						plaintext.lower()
					snake_case_						:Union[str, Any]								=						key.lower()
					snake_case_						:Any								=						0
					snake_case_						:str								=						0
					snake_case_						:Union[str, Any]								=						""
					while plaintext_iterator < len(_A							):
										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      A      (			_A,     _A							):




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

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

					snake_case_						:Tuple								=						key.lower()
					snake_case_						:Tuple								=						0
					snake_case_						:int								=						0
					snake_case_						:int								=						""
					while ciphertext_iterator < len(_A							):
										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()
				__UpperCAmelCase      :      Dict   					=					int(input('Type 1 to encrypt or 2 to decrypt:'))
				if operation == 1:
								__UpperCAmelCase      :      List[str]   					=					input('Typeplaintext to be encrypted:\n')
								__UpperCAmelCase      :      Optional[int]   					=					input('Type the key:\n')
								print(encrypt(plaintext, key))
				elif operation == 2:
								__UpperCAmelCase      :      List[Any]   					=					input('Type the ciphertext to be decrypted:\n')
								__UpperCAmelCase      :      Dict   					=					input('Type the key:\n')
								print(decrypt(ciphertext, key))
				decrypt('jsqqs avvwo', 'coffee')

