



"""simple docstring"""






import numpy as np
def      A      (			_A,     _A,     _A							):




					"""simple docstring"""
					snake_case_						:Union[str, Any]								=						n_draws * class_counts / class_counts.sum()
					# floored means we don't overshoot n_samples, but probably undershoot
					snake_case_						:Any								=						np.floor(_A							)
					# we add samples according to how much "left over" probability
					# they had, until we arrive at n_samples
					snake_case_						:Optional[Any]								=						int(n_draws - floored.sum()							)
					if need_to_add > 0:
										snake_case_						:Dict								=						continuous - floored
										snake_case_						:Optional[Any]								=						np.sort(np.unique(_A							)							)[::-1]
										# add according to remainder, but break ties
										# randomly to avoid biases
										for value in values:
															((snake_case_)	,  )						:Tuple								=						np.where(remainder == value							)
															# if we need_to_add less than what's in inds
															# we draw randomly from them.
															# if we need to add more, we add them all and
															# go to the next value
															snake_case_						:List[str]								=						min(len(_A							),     _A							)
															snake_case_						:List[str]								=						rng.choice(_A,     size=_A,     replace=_A							)
															floored[inds] += 1
															need_to_add -= add_now
															if need_to_add == 0:
																				break
					return floored.astype(np.intaa							)
def      A      (			_A,     _A,     _A,     _A,     _A=10							):




					"""simple docstring"""
					snake_case_	,  snake_case_						:Any								=						np.unique(_A,     return_inverse=_A							)
					snake_case_						:Optional[int]								=						classes.shape[0]
					snake_case_						:int								=						np.bincount(_A							)
					if np.min(_A							) < 2:
										raise ValueError("Minimum class count error"							)
					if n_train < n_classes:
										raise ValueError(
										    "The train_size = %d should be greater or " "equal to the number of classes = %d" % (n_train, n_classes)							)
					if n_test < n_classes:
										raise ValueError(
										    "The test_size = %d should be greater or " "equal to the number of classes = %d" % (n_test, n_classes)							)
					snake_case_						:str								=						np.split(np.argsort(_A,     kind="mergesort"							),     np.cumsum(_A							)[:-1]							)
					for _ in range(_A							):
										snake_case_						:Optional[Any]								=						approximate_mode(_A,     _A,     _A							)
										snake_case_						:Union[str, Any]								=						class_counts - n_i
										snake_case_						:Any								=						approximate_mode(_A,     _A,     _A							)

										snake_case_						:str								=						[]
										snake_case_						:Optional[int]								=						[]

										for i in range(_A							):
															snake_case_						:List[Any]								=						rng.permutation(class_counts[i]							)
															snake_case_						:Any								=						class_indices[i].take(_A,     mode="clip"							)
															train.extend(perm_indices_class_i[: n_i[i]]							)
															test.extend(perm_indices_class_i[n_i[i] : n_i[i] + t_i[i]]							)
										snake_case_						:Optional[Any]								=						rng.permutation(_A							)
										snake_case_						:str								=						rng.permutation(_A							)

										yield train, test






"""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')

