




"""simple docstring"""




from __future__ import annotations

from string import ascii_letters







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase = None					):
			__lowercase	:       Tuple				=   alphabet or ascii_letters

			# The final result string
			__lowercase	:       List[Any]				=   ''''''

			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
									__lowercase	:       Union[str, Any]				=   (alpha.index(__UpperCamelCase					) + key) % len(__UpperCamelCase					)

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

			return result







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase = None					):
			key *= -1

			return encrypt(__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase					)







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase = None					):
			__lowercase	:       List[Any]				=   alphabet or ascii_letters

			# To store data on all the combinations
			__lowercase	:       int				=   {}

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

			return brute_force_data


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

						# get user input
						a_            =   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":
									a_            =   input('Please enter the string to be encrypted: ')
									a_            =   int(input('Please enter off-set: ').strip())

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

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

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

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









"""simple docstring"""




import json
import os
import shutil
import tempfile
import unittest

from transformers import is_speech_available, is_torch_available
from transformers.models.speechta import SpeechTaTokenizer
from transformers.testing_utils import get_tests_dir, require_torch
from transformers.utils import FEATURE_EXTRACTOR_NAME


if is_speech_available() and is_torch_available():
			from transformers import SpeechTaFeatureExtractor, SpeechTaProcessor

			from .test_feature_extraction_speechta import floats_list


a_            =   get_tests_dir('fixtures/test_sentencepiece_bpe_char.model')

@require_torch
class        UpperCAmelCase_  (	unittest.TestCase						):
		def 					_lowerCamelCase    (		self   )		->   Dict:
					__lowercase	:       Union[str, Any]				=   tempfile.mkdtemp()

					__lowercase	:       List[str]				=   SpeechTaTokenizer(UpperCamelCase_   )
					tokenizer.save_pretrained(self.tmpdirname   )

					__lowercase	:       Dict				=   {
					    '''feature_size''': 1,
					    '''padding_value''': 0.0,
					    '''sampling_rate''': 1_60_00,
					    '''do_normalize''': False,
					    '''num_mel_bins''': 80,
					    '''hop_length''': 16,
					    '''win_length''': 64,
					    '''win_function''': '''hann_window''',
					    '''fmin''': 80,
					    '''fmax''': 76_00,
					    '''mel_floor''': 1E-10,
					    '''reduction_factor''': 2,
					    '''return_attention_mask''': True,
					}

					__lowercase	:       List[Any]				=   os.path.join(self.tmpdirname							,		UpperCamelCase_   )
					with open(self.feature_extraction_file							,		'''w'''							,		encoding='''utf-8'''   ) as fp:
								fp.write(json.dumps(UpperCamelCase_   ) + '''\n'''   )
		def 					_lowerCamelCase    (		self							,		**UpperCamelCase_   )		->   Union[str, Any]:
					return SpeechTaTokenizer.from_pretrained(self.tmpdirname							,		**UpperCamelCase_   )
		def 					_lowerCamelCase    (		self							,		**UpperCamelCase_   )		->   Optional[Any]:
					return SpeechTaFeatureExtractor.from_pretrained(self.tmpdirname							,		**UpperCamelCase_   )
		def 					_lowerCamelCase    (		self   )		->   Any:
					shutil.rmtree(self.tmpdirname   )
		def 					_lowerCamelCase    (		self   )		->   Union[str, Any]:
					__lowercase	:       List[str]				=   self.get_tokenizer()
					__lowercase	:       int				=   self.get_feature_extractor()

					__lowercase	:       Any				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					processor.save_pretrained(self.tmpdirname   )
					__lowercase	:       List[Any]				=   SpeechTaProcessor.from_pretrained(self.tmpdirname   )

					self.assertEqual(processor.tokenizer.get_vocab()							,		tokenizer.get_vocab()   )
					self.assertIsInstance(processor.tokenizer							,		UpperCamelCase_   )

					self.assertEqual(processor.feature_extractor.to_json_string()							,		feature_extractor.to_json_string()   )
					self.assertIsInstance(processor.feature_extractor							,		UpperCamelCase_   )
		def 					_lowerCamelCase    (		self   )		->   Optional[Any]:
					__lowercase	:       Optional[int]				=   SpeechTaProcessor(tokenizer=self.get_tokenizer()							,		feature_extractor=self.get_feature_extractor()   )
					processor.save_pretrained(self.tmpdirname   )

					__lowercase	:       str				=   self.get_tokenizer(bos_token='''(BOS)'''							,		eos_token='''(EOS)'''   )
					__lowercase	:       Dict				=   self.get_feature_extractor(do_normalize=UpperCamelCase_							,		padding_value=1.0   )

					__lowercase	:       Tuple				=   SpeechTaProcessor.from_pretrained(
					    self.tmpdirname							,		bos_token='''(BOS)'''							,		eos_token='''(EOS)'''							,		do_normalize=UpperCamelCase_							,		padding_value=1.0   )

					self.assertEqual(processor.tokenizer.get_vocab()							,		tokenizer_add_kwargs.get_vocab()   )
					self.assertIsInstance(processor.tokenizer							,		UpperCamelCase_   )

					self.assertEqual(processor.feature_extractor.to_json_string()							,		feature_extractor_add_kwargs.to_json_string()   )
					self.assertIsInstance(processor.feature_extractor							,		UpperCamelCase_   )
		def 					_lowerCamelCase    (		self   )		->   List[str]:
					__lowercase	:       Optional[Any]				=   self.get_feature_extractor()
					__lowercase	:       Optional[Any]				=   self.get_tokenizer()

					__lowercase	:       Union[str, Any]				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					__lowercase	:       int				=   floats_list((3, 10_00)   )

					__lowercase	:       str				=   feature_extractor(audio=UpperCamelCase_							,		return_tensors='''np'''   )
					__lowercase	:       Dict				=   processor(audio=UpperCamelCase_							,		return_tensors='''np'''   )

					for key in input_feat_extract.keys():
								self.assertAlmostEqual(input_feat_extract[key].sum()							,		input_processor[key].sum()							,		delta=1E-2   )
		def 					_lowerCamelCase    (		self   )		->   List[Any]:
					__lowercase	:       str				=   self.get_feature_extractor()
					__lowercase	:       str				=   self.get_tokenizer()

					__lowercase	:       Union[str, Any]				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					__lowercase	:       Optional[int]				=   floats_list((3, 10_00)   )

					__lowercase	:       List[str]				=   feature_extractor(audio_target=UpperCamelCase_							,		return_tensors='''np'''   )
					__lowercase	:       List[str]				=   processor(audio_target=UpperCamelCase_							,		return_tensors='''np'''   )

					for key in input_feat_extract.keys():
								self.assertAlmostEqual(input_feat_extract[key].sum()							,		input_processor[key].sum()							,		delta=1E-2   )
		def 					_lowerCamelCase    (		self   )		->   Any:
					__lowercase	:       List[Any]				=   self.get_feature_extractor()
					__lowercase	:       List[str]				=   self.get_tokenizer()

					__lowercase	:       Union[str, Any]				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					__lowercase	:       List[str]				=   '''This is a test string'''

					__lowercase	:       Any				=   processor(text=UpperCamelCase_   )
					__lowercase	:       Optional[int]				=   tokenizer(UpperCamelCase_   )

					for key in encoded_tok.keys():
								self.assertListEqual(encoded_tok[key]							,		encoded_processor[key]   )
		def 					_lowerCamelCase    (		self   )		->   str:
					__lowercase	:       int				=   self.get_feature_extractor()
					__lowercase	:       List[str]				=   self.get_tokenizer()

					__lowercase	:       List[Any]				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					__lowercase	:       Union[str, Any]				=   '''This is a test string'''

					__lowercase	:       Tuple				=   processor(text_target=UpperCamelCase_   )
					__lowercase	:       Optional[int]				=   tokenizer(UpperCamelCase_   )

					for key in encoded_tok.keys():
								self.assertListEqual(encoded_tok[key]							,		encoded_processor[key]   )
		def 					_lowerCamelCase    (		self   )		->   Optional[Any]:
					__lowercase	:       Optional[int]				=   self.get_feature_extractor()
					__lowercase	:       str				=   self.get_tokenizer()

					__lowercase	:       int				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					__lowercase	:       Optional[Any]				=   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

					__lowercase	:       str				=   processor.batch_decode(UpperCamelCase_   )
					__lowercase	:       int				=   tokenizer.batch_decode(UpperCamelCase_   )

					self.assertListEqual(UpperCamelCase_							,		UpperCamelCase_   )
		def 					_lowerCamelCase    (		self   )		->   Optional[int]:
					__lowercase	:       Union[str, Any]				=   self.get_feature_extractor()
					__lowercase	:       int				=   self.get_tokenizer()

					__lowercase	:       Optional[int]				=   SpeechTaProcessor(tokenizer=UpperCamelCase_							,		feature_extractor=UpperCamelCase_   )

					self.assertListEqual(
					    processor.model_input_names							,		feature_extractor.model_input_names							,		msg='''`processor` and `feature_extractor` model input names do not match'''							,		)



