






import json
import os
import tempfile

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features import ArrayaD
from utils import generate_examples, get_duration


UpperCamelCase												=      (30, 487)
UpperCamelCase												=      (36, 1_024)
UpperCamelCase												=      (100, 100)
UpperCamelCase												=      100

UpperCamelCase												=      datasets.Features(
    {'''text''': ArrayaD(SHAPE_TEST_1, dtype='''float32'''), '''image''': ArrayaD(SHAPE_TEST_2, dtype='''float32''')}
)

UpperCamelCase							,       UpperCamelCase												=      os.path.split(__file__)
UpperCamelCase												=      os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))

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






						"""simple docstring"""





						with ArrowWriter(features=snake_case__			,path=os.path.join(snake_case__			,"""beta.arrow"""						)						) as writer:
												for key, record in dummy_data:
																		_SCREAMING_SNAKE_CASE       =    my_features.encode_example(snake_case__						)
																		writer.write(snake_case__						)
												_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE       =    writer.finalize()

@get_duration
def 			__lowerCamelCase     (						snake_case__			,snake_case__						)				->    List[Any]:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    datasets.Dataset.from_file(
						    filename=os.path.join(snake_case__			,"""beta.arrow"""						)			,info=datasets.DatasetInfo(features=snake_case__						)						)
						for _ in dataset:
												pass

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






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    datasets.Dataset.from_file(
						    filename=os.path.join(snake_case__			,"""beta.arrow"""						)			,info=datasets.DatasetInfo(features=snake_case__						)						)
						dataset.set_format("""numpy"""						)
						for _ in dataset:
												pass

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






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    10
						_SCREAMING_SNAKE_CASE       =    datasets.Dataset.from_file(
						    filename=os.path.join(snake_case__			,"""beta.arrow"""						)			,info=datasets.DatasetInfo(features=snake_case__						)						)
						for i in range(0			,len(snake_case__						)			,snake_case__						):
												_SCREAMING_SNAKE_CASE       =    dataset[i : i + batch_size]

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






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    10
						_SCREAMING_SNAKE_CASE       =    datasets.Dataset.from_file(
						    filename=os.path.join(snake_case__			,"""beta.arrow"""						)			,info=datasets.DatasetInfo(features=snake_case__						)						)
						dataset.set_format("""numpy"""						)
						for i in range(0			,len(snake_case__						)			,snake_case__						):
												_SCREAMING_SNAKE_CASE       =    dataset[i : i + batch_size]

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






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    datasets.Dataset.from_file(
						    filename=os.path.join(snake_case__			,"""beta.arrow"""						)			,info=datasets.DatasetInfo(features=snake_case__						)						)
						for col in feats:
												_SCREAMING_SNAKE_CASE       =    dataset[col]

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






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    datasets.Dataset.from_file(
						    filename=os.path.join(snake_case__			,"""beta.arrow"""						)			,info=datasets.DatasetInfo(features=snake_case__						)						)
						dataset.set_format("""numpy"""						)
						for col in feats:
												_SCREAMING_SNAKE_CASE       =    dataset[col]

def 			__lowerCamelCase     (						)				->    Optional[Any]:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    {}
						_SCREAMING_SNAKE_CASE       =    (
						    read_unformated,
						    read_formatted_as_numpy,
						    read_batch_unformated,
						    read_batch_formatted_as_numpy,
						    read_col_unformated,
						    read_col_formatted_as_numpy,
						)
						with tempfile.TemporaryDirectory() as tmp_dir:
												_SCREAMING_SNAKE_CASE       =    datasets.Features({"""image""": ArrayaD(snake_case__			,dtype="""float32"""						)}						)
												_SCREAMING_SNAKE_CASE       =    generate_examples(features=snake_case__			,num_examples=snake_case__						)
												_SCREAMING_SNAKE_CASE       =    write(snake_case__			,snake_case__			,snake_case__						)
												for read_func in read_functions:
																		_SCREAMING_SNAKE_CASE       =    read_func(snake_case__			,snake_case__						)

						with tempfile.TemporaryDirectory() as tmp_dir:
												# don't use fixed length for fair comparison
												# feats = datasets.Features(
												#     {"image": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), SPEED_TEST_SHAPE[1]), SPEED_TEST_SHAPE[0])}
												# )
												_SCREAMING_SNAKE_CASE       =    datasets.Features({"""image""": datasets.Sequence(datasets.Sequence(datasets.Value("""float32"""						)						)						)}						)
												_SCREAMING_SNAKE_CASE       =    generate_examples(
												    features=snake_case__			,num_examples=snake_case__			,seq_shapes={"""image""": SPEED_TEST_SHAPE}						)
												_SCREAMING_SNAKE_CASE       =    write(snake_case__			,snake_case__			,snake_case__						)
												for read_func in read_functions:
																		_SCREAMING_SNAKE_CASE       =    read_func(snake_case__			,snake_case__						)

						with tempfile.TemporaryDirectory() as tmp_dir:
												# don't use fixed length for fair comparison
												# feats = datasets.Features(
												#     {"image": datasets.Sequence(datasets.Value("float32"), SPEED_TEST_SHAPE[0] * SPEED_TEST_SHAPE[1])}
												# )
												_SCREAMING_SNAKE_CASE       =    datasets.Features({"""image""": datasets.Sequence(datasets.Value("""float32"""						)						)}						)
												_SCREAMING_SNAKE_CASE       =    generate_examples(
												    features=snake_case__			,num_examples=snake_case__			,seq_shapes={"""image""": [SPEED_TEST_SHAPE[0] * SPEED_TEST_SHAPE[1]]}			,)
												_SCREAMING_SNAKE_CASE       =    write(snake_case__			,snake_case__			,snake_case__						)
												for read_func in read_functions:
																		_SCREAMING_SNAKE_CASE       =    read_func(snake_case__			,snake_case__						)

						with open(snake_case__			,"""wb"""						) as f:
												f.write(json.dumps(snake_case__						).encode("""utf-8"""						)						)


if __name__ == "__main__":  # useful to run the profiler
		benchmark_array_xd()









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

