






import dataclasses
import enum
import functools
import math
import re

# The following script is adapted from the script of TaPas.
# Original: https://github.com/google-research/tapas/master/wikisql_utils.py
from typing import Any, List, Text


UpperCamelCase												=      '''none'''
UpperCamelCase												=      '''none'''

def 			__lowerCamelCase     (						snake_case__			,snake_case__						)				->    Dict:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    value.split(snake_case__						)
						return len(snake_case__						) > 1 and any((len(snake_case__						) == 3 for x in split)						)

def 			__lowerCamelCase     (						snake_case__						)				->    Optional[Any]:






						"""simple docstring"""





						if isinstance(snake_case__			,snake_case__						):
												return value
						if isinstance(snake_case__			,snake_case__						):
												return float(snake_case__						)
						if not isinstance(snake_case__			,snake_case__						):
												raise ValueError("""Argument value is not a string. Can't parse it as float"""						)
						_SCREAMING_SNAKE_CASE       =    value

						try:
												# Example: 1,000.7
												if "." in sanitized and "," in sanitized:
																		return float(sanitized.replace(""","""			,""""""						)						)
												# 1,000
												if "," in sanitized and _split_thousands(""","""			,snake_case__						):
																		return float(sanitized.replace(""","""			,""""""						)						)
												# 5,5556
												if "," in sanitized and sanitized.count(""","""						) == 1 and not _split_thousands(""","""			,snake_case__						):
																		return float(sanitized.replace(""","""			,"""."""						)						)
												# 0.0.0.1
												if sanitized.count("""."""						) > 1:
																		return float(sanitized.replace("""."""			,""""""						)						)
												# 0,0,0,1
												if sanitized.count(""","""						) > 1:
																		return float(sanitized.replace(""","""			,""""""						)						)
												return float(snake_case__						)
						except ValueError:
												# Avoid adding the sanitized value in the error message.
												raise ValueError("""Unable to convert value to float"""						)

def 			__lowerCamelCase     (						snake_case__						)				->    Any:






						"""simple docstring"""





						if answer is None:
												return None
						try:
												_SCREAMING_SNAKE_CASE       =    convert_to_float(snake_case__						)
												if isinstance(snake_case__			,snake_case__						) and math.isnan(snake_case__						):
																		return None
												return value
						except ValueError:
												return answer.lower()


UpperCamelCase												=      {
    '''text''': lambda x: x,
    '''real''': convert_to_float,
}



class  __UpperCAmelCase						(enum.Enum       ):
			__snake_case							: int							=				0
			__snake_case							: Tuple							=				1
			__snake_case							: Union[str, Any]							=				2
			__snake_case							: Optional[int]							=				3
			__snake_case							: Optional[Any]							=				4
			__snake_case							: Dict							=				5



class  __UpperCAmelCase						(enum.Enum       ):
			__snake_case							: Tuple							=				0
			__snake_case							: Any							=				1
			__snake_case							: Optional[Any]							=				2



@dataclasses.dataclass
class  __UpperCAmelCase						:
			__snake_case							: Text
			__snake_case							: _Operator
			__snake_case							: Any
UpperCamelCase												=      re.compile(R'''\w+|[^\w\s]+''', re.UNICODE | re.MULTILINE | re.DOTALL)

def 			__lowerCamelCase     (						snake_case__						)				->    Optional[int]:






						"""simple docstring"""





						return list(_TOKENIZER.findall(x.lower()						)						)

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__						)				->    Tuple:






						"""simple docstring"""





						if operator == _Operator.EQUALS:
												return src == tgt
						elif operator == _Operator.GREATER:
												return src > tgt
						elif operator == _Operator.LESSER:
												return src < tgt
						raise ValueError(F'Unknown operator: {operator}'						)

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__						)				->    Tuple:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    table["""types"""]
						return _TYPE_CONVERTER[types[column]](snake_case__						)

def 			__lowerCamelCase     (						snake_case__						)				->    Dict:






						"""simple docstring"""





						return isinstance(snake_case__			,snake_case__						)

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__						)				->    int:






						"""simple docstring"""





						for cond in conditions:
												_SCREAMING_SNAKE_CASE       =    row[cond.column]

												_SCREAMING_SNAKE_CASE       =    _parse_value(snake_case__			,cond.column			,cond.cmp_value						)

												if _is_string(snake_case__						) and _is_string(snake_case__						):
																		_SCREAMING_SNAKE_CASE       =    _normalize_for_match(snake_case__						)
																		_SCREAMING_SNAKE_CASE       =    _normalize_for_match(snake_case__						)

												if not isinstance(snake_case__			,type(snake_case__						)						):
																		raise ValueError("""Type difference {} != {}""".format(type(snake_case__						)			,type(snake_case__						)						)						)

												if not _compare(cond.operator			,snake_case__			,snake_case__						):
																		return False
						return True

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__						)				->    Dict:






						"""simple docstring"""





						if not answer_coordinates:
												if aggregation_op == _Aggregation.COUNT:
																		return 0.0
												else:
																		return EMPTY_ANSWER_AGG

    # Count can support non numeric answers.
						if aggregation_op == _Aggregation.COUNT:
												return float(len(snake_case__						)						)

						# If we have just one answer, if float returns it or try a conversion.
						_SCREAMING_SNAKE_CASE       =    [table["""rows"""][i][j] for (i, j) in answer_coordinates]
						if len(snake_case__						) == 1:
												try:
																		return convert_to_float(values[0]						)
												except ValueError as e:
																		if aggregation_op != _Aggregation.NONE:
																								raise e

						if aggregation_op == _Aggregation.NONE:
												return None

						# Other aggregation only support numeric values. Bail out if we have strings.
						if not all((isinstance(snake_case__			,(int, float)						) for v in values)						):
												return None

						if aggregation_op == _Aggregation.SUM:
												return float(sum(snake_case__						)						)
						elif aggregation_op == _Aggregation.AVERAGE:
												return sum(snake_case__						) / len(snake_case__						)
						else:
												raise ValueError(F'Unknown aggregation: {aggregation_op}'						)

def 			__lowerCamelCase     (						snake_case__			,snake_case__						)				->    Union[str, Any]:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    sql_query["""agg"""]
						if aggregation_op_index >= 3:
												_SCREAMING_SNAKE_CASE       =    _Aggregation(snake_case__						)
						else:
												_SCREAMING_SNAKE_CASE       =    _Aggregation.NONE

						_SCREAMING_SNAKE_CASE       =    sql_query["""sel"""]
						_SCREAMING_SNAKE_CASE       =    [
						    _Condition(snake_case__			,_Operator(snake_case__						)			,snake_case__						)
						    for column, operator, cmp_value in zip(
						        sql_query["""conds"""]["""column_index"""]			,sql_query["""conds"""]["""operator_index"""]			,sql_query["""conds"""]["""condition"""]						)
						]

						_SCREAMING_SNAKE_CASE       =    []
						for row in range(len(table["""rows"""]						)						):
												if _respect_conditions(snake_case__			,table["""rows"""][row]			,snake_case__						):
																		indices.append((row, target_column)						)

						if not indices:
												return [], aggregation_op

						if len(snake_case__						) == 1:
												return indices, aggregation_op

						# Parsing of MIN/MAX.
						if aggregation_op_index in (1, 2):
												_SCREAMING_SNAKE_CASE       =    {2: min, 1: max}
												_SCREAMING_SNAKE_CASE       =    [(table["""rows"""][i][j], index) for index, (i, j) in enumerate(snake_case__						)]
												_SCREAMING_SNAKE_CASE       =    functools.reduce(operators[sql_query["""agg"""]]			,snake_case__						)

												_SCREAMING_SNAKE_CASE       =    [indices[reduced[1]]]
												return ret, _Aggregation.NONE

						return indices, aggregation_op

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__						)				->    List[str]:






						"""simple docstring"""





						if float_answer is not None:
												return [str(snake_case__						)]
						return [str(table["""real_rows"""][r][c]						) for r, c in answer_coordinates]




def 			__lowerCamelCase     (						snake_case__			,snake_case__						)				->    List:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE       =    _get_answer_coordinates(snake_case__			,snake_case__						)
						_SCREAMING_SNAKE_CASE       =    _get_float_answer(snake_case__			,snake_case__			,snake_case__						)
						_SCREAMING_SNAKE_CASE       =    _get_answer_text(snake_case__			,snake_case__			,snake_case__						)
						# keep the original data the same with TaPas
						if len(snake_case__						) == 0:
												_SCREAMING_SNAKE_CASE       =    [EMPTY_ANSWER]
						return answer_text









from __future__ import annotations

from string import ascii_letters

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__ = None						)				->    str:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    alphabet or ascii_letters

						# The final result string
						_SCREAMING_SNAKE_CASE       =    """"""

						for character in input_string:
												if character not in alpha:
																		# Append without encryption if character is not in the alphabet
																		result += character
												else:
																		# Get the index of the new key and make sure it isn't too large
																		_SCREAMING_SNAKE_CASE       =    (alpha.index(snake_case__						) + key) % len(snake_case__						)

																		# Append the encoded character to the alphabet
																		result += alpha[new_key]

						return result

def 			__lowerCamelCase     (						snake_case__			,snake_case__			,snake_case__ = None						)				->    str:






						"""simple docstring"""





						key *= -1

						return encrypt(snake_case__			,snake_case__			,snake_case__						)

def 			__lowerCamelCase     (						snake_case__			,snake_case__ = None						)				->    dict[int, str]:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    alphabet or ascii_letters

						# To store data on all the combinations
						_SCREAMING_SNAKE_CASE       =    {}

						# Cycle through each combination
						for key in range(1			,len(snake_case__						) + 1						):
												# Decrypt the message and store the result in the data
												_SCREAMING_SNAKE_CASE       =    decrypt(snake_case__			,snake_case__			,snake_case__						)

						return brute_force_data


if __name__ == "__main__":
		while True:
				print(f"\n{'-' * 10}\n Menu\n{'-' * 10}")
				print(*['''1.Encrypt''', '''2.Decrypt''', '''3.BruteForce''', '''4.Quit'''], sep='''\n''')

				# get user input
				UpperCamelCase												=      input('''\nWhat would you like to do?: ''').strip() or '''4'''

				# run functions based on what the user chose
				if choice not in ("1", "2", "3", "4"):
						print('''Invalid choice, please enter a valid choice''')
				elif choice == "1":
						UpperCamelCase												=      input('''Please enter the string to be encrypted: ''')
						UpperCamelCase												=      int(input('''Please enter off-set: ''').strip())

						print(encrypt(input_string, key))
				elif choice == "2":
						UpperCamelCase												=      input('''Please enter the string to be decrypted: ''')
						UpperCamelCase												=      int(input('''Please enter off-set: ''').strip())

						print(decrypt(input_string, key))
				elif choice == "3":
						UpperCamelCase												=      input('''Please enter the string to be decrypted: ''')
						UpperCamelCase												=      brute_force(input_string)

						for key, value in brute_force_data.items():
								print(f"Key: {key} | Message: {value}")

				elif choice == "4":
						print('''Goodbye.''')
						break

