
from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve






def  a_	( __lowercase     :			Tuple ,      __lowercase     :			str ,      __lowercase     :			int				)				->						List[Any]:
			_snake_case						=    np.stack((horizontal_flow, vertical_flow) ,      2				)

			# Create a grid of all pixel coordinates and subtract the flow to get the
			# target pixels coordinates
			_snake_case						=    np.stack(
			    np.meshgrid(np.arange(0 ,      image.shape[1]				) ,      np.arange(0 ,      image.shape[0]				)				) ,      2				)
			_snake_case						=    np.round(grid - flow				).astype(np.intaa				)

			# Find the locations outside of the original image
			_snake_case						=    (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]				))
			_snake_case						=    0

			_snake_case						=    image[grid[:, :, 1], grid[:, :, 0]]

			# Set pixels at invalid locations to 0
			_snake_case						=    0

			return warped






def  a_	( __lowercase     :			Dict ,      __lowercase     :			List[Any] ,      __lowercase     :			Tuple ,      __lowercase     :			Optional[Any] = None ,      )				->						List[str]:






			if alpha is None:
						_snake_case						=    0.1

			# Initialize flow
			_snake_case						=    np.zeros_like(UpperCamelCase__				)
			_snake_case						=    np.zeros_like(UpperCamelCase__				)

			# Prepare kernels for the calculation of the derivatives and the average velocity
			_snake_case						=    np.array([[-1, 1], [-1, 1]]				) * 0.2_5
			_snake_case						=    np.array([[-1, -1], [1, 1]]				) * 0.2_5
			_snake_case						=    np.array([[1, 1], [1, 1]]				) * 0.2_5
			_snake_case						=    np.array(
			    [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]				)

			# Iteratively refine the flow
			for _ in range(UpperCamelCase__				):
						_snake_case						=    warp(UpperCamelCase__ ,      UpperCamelCase__ ,      UpperCamelCase__				)
						_snake_case						=    convolve(UpperCamelCase__ ,      UpperCamelCase__				) + convolve(UpperCamelCase__ ,      UpperCamelCase__				)
						_snake_case						=    convolve(UpperCamelCase__ ,      UpperCamelCase__				) + convolve(UpperCamelCase__ ,      UpperCamelCase__				)
						_snake_case						=    convolve(UpperCamelCase__ ,      UpperCamelCase__				) + convolve(UpperCamelCase__ ,      -kernel_t				)

						_snake_case						=    convolve(UpperCamelCase__ ,      UpperCamelCase__				)
						_snake_case						=    convolve(UpperCamelCase__ ,      UpperCamelCase__				)

						# This updates the flow as proposed in the paper (Step 12)
						_snake_case						=    (
						    derivative_x * avg_horizontal_velocity
						    + derivative_y * avg_vertical_velocity
						    + derivative_t
						)
						_snake_case						=    update / (alpha**2 + derivative_x**2 + derivative_y**2)

						_snake_case						=    avg_horizontal_velocity - derivative_x * update
						_snake_case						=    avg_vertical_velocity - derivative_y * update

			return horizontal_flow, vertical_flow


if __name__ == "__main__":
			import doctest

			doctest.testmod()

import random
import sys

_lowerCamelCase :       Tuple     					=    '''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''






def  a_	( )				->						None:
			_snake_case						=    input('Enter message: '				)
			_snake_case						=    'LFWOAYUISVKMNXPBDCRJTQEGHZ'
			_snake_case						=    input('Encrypt/Decrypt [e/d]: '				)

			check_valid_key(__lowercase				)

			if resp.lower().startswith('e'				):
						_snake_case						=    'encrypt'
						_snake_case						=    encrypt_message(__lowercase ,      __lowercase				)
			elif resp.lower().startswith('d'				):
						_snake_case						=    'decrypt'
						_snake_case						=    decrypt_message(__lowercase ,      __lowercase				)

			print(f'''\n{mode.title()}ion: \n{translated}'''				)






def  a_	( __lowercase     :			str				)				->						None:
			_snake_case						=    list(__lowercase				)
			_snake_case						=    list(__lowercase				)
			key_list.sort()
			letters_list.sort()

			if key_list != letters_list:
						sys.exit('Error in the key or symbol set.'				)






def  a_	( __lowercase     :			str ,      __lowercase     :			str				)				->						str:
			return translate_message(__lowercase ,      __lowercase ,      'encrypt'				)






def  a_	( __lowercase     :			str ,      __lowercase     :			str				)				->						str:
			return translate_message(__lowercase ,      __lowercase ,      'decrypt'				)






def  a_	( __lowercase     :			str ,      __lowercase     :			str ,      __lowercase     :			str				)				->						str:
			_snake_case						=    ''
			_snake_case						=    LETTERS
			_snake_case						=    key

			if mode == "decrypt":
						_snake_case			,      _snake_case						=    chars_b, chars_a

			for symbol in message:
						if symbol.upper() in chars_a:
									_snake_case						=    chars_a.find(symbol.upper()				)
									if symbol.isupper():
												translated += chars_b[sym_index].upper()
									else:
												translated += chars_b[sym_index].lower()
						else:
									translated += symbol

			return translated






def  a_	( )				->						str:
			_snake_case						=    list(__lowercase				)
			random.shuffle(__lowercase				)
			return "".join(__lowercase				)


if __name__ == "__main__":
			main()