


"""simple docstring"""





import os
from typing import List, Union

import tensorflow as tf
from tensorflow_text import BertTokenizer as BertTokenizerLayer
from tensorflow_text import FastBertTokenizer, ShrinkLongestTrimmer, case_fold_utfa, combine_segments, pad_model_inputs

from .tokenization_bert import BertTokenizer



class 		snake_case_(							tf.keras.layers.Layer      ):






     def __init__(						self	:       Optional[int]       ,					UpperCamelCase_	:       List       ,					UpperCamelCase_	:       bool       ,					UpperCamelCase_	:       int = None       ,					UpperCamelCase_	:       int = None       ,					UpperCamelCase_	:       int = None       ,					UpperCamelCase_	:       str = "longest"       ,					UpperCamelCase_	:       bool = True       ,					UpperCamelCase_	:       int = 5_1_2       ,					UpperCamelCase_	:       int = None       ,					UpperCamelCase_	:       bool = True       ,					UpperCamelCase_	:       bool = True       ,					UpperCamelCase_	:       bool = True       ,					**UpperCamelCase_	:       Any       ,					):
           super().__init__()
           if use_fast_bert_tokenizer:
                 lowerCAmelCase       :						Optional[Any]							= FastBertTokenizer(
                     _SCREAMING_SNAKE_CASE       ,					token_out_type=tf.intaa       ,					lower_case_nfd_strip_accents=_SCREAMING_SNAKE_CASE       ,					**_SCREAMING_SNAKE_CASE					)
           else:
                 lowerCAmelCase       :						Tuple							= tf.lookup.StaticVocabularyTable(
                     tf.lookup.KeyValueTensorInitializer(
                         keys=_SCREAMING_SNAKE_CASE       ,					key_dtype=tf.string       ,					values=tf.range(tf.size(_SCREAMING_SNAKE_CASE       ,					out_type=tf.intaa					)       ,					dtype=tf.intaa					)       ,					value_dtype=tf.intaa       ,					)       ,					num_oov_buckets=1       ,					)
                 lowerCAmelCase       :						Union[str, Any]							= BertTokenizerLayer(
                     _SCREAMING_SNAKE_CASE       ,					token_out_type=tf.intaa       ,					lower_case=_SCREAMING_SNAKE_CASE       ,					**_SCREAMING_SNAKE_CASE					)

           lowerCAmelCase       :						Tuple							= vocab_list
           lowerCAmelCase       :						Union[str, Any]							= do_lower_case
           lowerCAmelCase       :						Dict							= cls_token_id or vocab_list.index('''[CLS]'''					)
           lowerCAmelCase       :						Optional[Any]							= sep_token_id or vocab_list.index('''[SEP]'''					)
           lowerCAmelCase       :						List[Any]							= pad_token_id or vocab_list.index('''[PAD]'''					)
           lowerCAmelCase       :						List[Any]							= ShrinkLongestTrimmer(max_length - 3       ,					axis=1					)  # Allow room for special tokens
           lowerCAmelCase       :						List[Any]							= max_length
           lowerCAmelCase       :						List[Any]							= padding
           lowerCAmelCase       :						List[str]							= truncation
           lowerCAmelCase       :						int							= pad_to_multiple_of
           lowerCAmelCase       :						int							= return_token_type_ids
           lowerCAmelCase       :						Tuple							= return_attention_mask






     @classmethod
     def   lowerCamelCase__  (						cls	:       Union[str, Any]       ,					UpperCamelCase_	:       "PreTrainedTokenizerBase"       ,					**UpperCamelCase_	:       List[Any]					):  # noqa: F821
           lowerCAmelCase       :						int							= kwargs.pop('''do_lower_case'''       ,					_SCREAMING_SNAKE_CASE					)
           lowerCAmelCase       :						List[Any]							= tokenizer.do_lower_case if do_lower_case is None else do_lower_case
           lowerCAmelCase       :						Optional[Any]							= kwargs.pop('''cls_token_id'''       ,					_SCREAMING_SNAKE_CASE					)
           lowerCAmelCase       :						Dict							= tokenizer.cls_token_id if cls_token_id is None else cls_token_id
           lowerCAmelCase       :						Dict							= kwargs.pop('''sep_token_id'''       ,					_SCREAMING_SNAKE_CASE					)
           lowerCAmelCase       :						Optional[int]							= tokenizer.sep_token_id if sep_token_id is None else sep_token_id
           lowerCAmelCase       :						str							= kwargs.pop('''pad_token_id'''       ,					_SCREAMING_SNAKE_CASE					)
           lowerCAmelCase       :						Tuple							= tokenizer.pad_token_id if pad_token_id is None else pad_token_id

           lowerCAmelCase       :						str							= tokenizer.get_vocab()
           lowerCAmelCase       :						Tuple							= sorted([(wordpiece, idx) for wordpiece, idx in vocab.items()]       ,					key=lambda UpperCamelCase_					: x[1]					)
           lowerCAmelCase       :						int							= [entry[0] for entry in vocab]
           return cls(
               vocab_list=_SCREAMING_SNAKE_CASE       ,					do_lower_case=_SCREAMING_SNAKE_CASE       ,					cls_token_id=_SCREAMING_SNAKE_CASE       ,					sep_token_id=_SCREAMING_SNAKE_CASE       ,					pad_token_id=_SCREAMING_SNAKE_CASE       ,					**_SCREAMING_SNAKE_CASE       ,					)






     @classmethod
     def   lowerCamelCase__  (						cls	:       int       ,					UpperCamelCase_	:       Union[str, os.PathLike]       ,					*UpperCamelCase_	:       Dict       ,					**UpperCamelCase_	:       Optional[int]					):
           try:
                 lowerCAmelCase       :						Optional[Any]							= BertTokenizer.from_pretrained(_SCREAMING_SNAKE_CASE       ,					*_SCREAMING_SNAKE_CASE       ,					**_SCREAMING_SNAKE_CASE					)
           except:  # noqa: E722
                 from .tokenization_bert_fast import BertTokenizerFast

                 lowerCAmelCase       :						Union[str, Any]							= BertTokenizerFast.from_pretrained(_SCREAMING_SNAKE_CASE       ,					*_SCREAMING_SNAKE_CASE       ,					**_SCREAMING_SNAKE_CASE					)
           return cls.from_tokenizer(_SCREAMING_SNAKE_CASE       ,					**_SCREAMING_SNAKE_CASE					)






     def   lowerCamelCase__  (						self	:       Any       ,					UpperCamelCase_	:       List[str]					):
           if self.do_lower_case:
                 lowerCAmelCase       :						Dict							= case_fold_utfa(_SCREAMING_SNAKE_CASE					)
           lowerCAmelCase       :						List[str]							= self.tf_tokenizer.tokenize(_SCREAMING_SNAKE_CASE					)
           return tokens.merge_dims(1       ,					-1					)






     def   lowerCamelCase__  (						self	:       Tuple       ,					UpperCamelCase_	:       int       ,					UpperCamelCase_	:       Union[str, Any]=None       ,					UpperCamelCase_	:       Optional[int]=None       ,					UpperCamelCase_	:       Dict=None       ,					UpperCamelCase_	:       Union[str, Any]=None       ,					UpperCamelCase_	:       str=None       ,					UpperCamelCase_	:       Any=None       ,					UpperCamelCase_	:       int=None       ,					):
           if padding is None:
                 lowerCAmelCase       :						List[str]							= self.padding
           if padding not in ("longest", "max_length"):
                 raise ValueError('''Padding must be either \'longest\' or \'max_length\'!'''					)
           if max_length is not None and text_pair is not None:
                 # Because we have to instantiate a Trimmer to do it properly
                 raise ValueError('''max_length cannot be overridden at call time when truncating paired texts!'''					)
           if max_length is None:
                 lowerCAmelCase       :						Any							= self.max_length
           if truncation is None:
                 lowerCAmelCase       :						int							= self.truncation
           if pad_to_multiple_of is None:
                 lowerCAmelCase       :						Tuple							= self.pad_to_multiple_of
           if return_token_type_ids is None:
                 lowerCAmelCase       :						Dict							= self.return_token_type_ids
           if return_attention_mask is None:
                 lowerCAmelCase       :						List[Any]							= self.return_attention_mask
           if not isinstance(_SCREAMING_SNAKE_CASE       ,					tf.Tensor					):
                 lowerCAmelCase       :						Dict							= tf.convert_to_tensor(_SCREAMING_SNAKE_CASE					)
           if text_pair is not None and not isinstance(_SCREAMING_SNAKE_CASE       ,					tf.Tensor					):
                 lowerCAmelCase       :						Tuple							= tf.convert_to_tensor(_SCREAMING_SNAKE_CASE					)
           if text_pair is not None:
                 if text.shape.rank > 1:
                       raise ValueError('''text argument should not be multidimensional when a text pair is supplied!'''					)
                 if text_pair.shape.rank > 1:
                       raise ValueError('''text_pair should not be multidimensional!'''					)
           if text.shape.rank == 2:
                 lowerCAmelCase       :						List[Any]							= text[:, 0], text[:, 1]
           lowerCAmelCase       :						str							= self.unpaired_tokenize(_SCREAMING_SNAKE_CASE					)
           if text_pair is None:  # Unpaired text
                 if truncation:
                       lowerCAmelCase       :						List[Any]							= text[:, : max_length - 2]  # Allow room for special tokens
                 lowerCAmelCase       :						Optional[int]							= combine_segments(
                     (text,)       ,					start_of_sequence_id=self.cls_token_id       ,					end_of_segment_id=self.sep_token_id					)
           else:  # Paired text
                 lowerCAmelCase       :						List[Any]							= self.unpaired_tokenize(_SCREAMING_SNAKE_CASE					)
                 if truncation:
                       lowerCAmelCase       :						Optional[int]							= self.paired_trimmer.trim([text, text_pair]					)
                 lowerCAmelCase       :						Dict							= combine_segments(
                     (text, text_pair)       ,					start_of_sequence_id=self.cls_token_id       ,					end_of_segment_id=self.sep_token_id					)
           if padding == "longest":
                 lowerCAmelCase       :						Dict							= input_ids.bounding_shape(axis=1					)
                 if pad_to_multiple_of is not None:
                       # No ceiling division in tensorflow, so we negate floordiv instead
                       lowerCAmelCase       :						Union[str, Any]							= pad_to_multiple_of * (-tf.math.floordiv(-pad_length       ,					_SCREAMING_SNAKE_CASE					))
           else:
                 lowerCAmelCase       :						List[str]							= max_length

           lowerCAmelCase       :						List[str]							= pad_model_inputs(_SCREAMING_SNAKE_CASE       ,					max_seq_length=_SCREAMING_SNAKE_CASE       ,					pad_value=self.pad_token_id					)
           lowerCAmelCase       :						Optional[Any]							= {'''input_ids''': input_ids}
           if return_attention_mask:
                 lowerCAmelCase       :						List[Any]							= attention_mask
           if return_token_type_ids:
                 lowerCAmelCase       :						str							= pad_model_inputs(
                     _SCREAMING_SNAKE_CASE       ,					max_seq_length=_SCREAMING_SNAKE_CASE       ,					pad_value=self.pad_token_id					)
                 lowerCAmelCase       :						Tuple							= token_type_ids
           return output






     def   lowerCamelCase__  (						self	:       List[Any]					):
           return {
               "vocab_list": self.vocab_list,
               "do_lower_case": self.do_lower_case,
               "cls_token_id": self.cls_token_id,
               "sep_token_id": self.sep_token_id,
               "pad_token_id": self.pad_token_id,
           }






from __future__ import annotations

from string import ascii_letters






def 	lowerCamelCase_       (			_a      ,  _a      ,  _a = None			):




		"""simple docstring"""






		lowerCAmelCase__  :     List[Any]       	=   alphabet or ascii_letters

		# The final result string
		lowerCAmelCase__  :     Optional[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
						lowerCAmelCase__  :     int       	=   (alpha.index(_a			) + key) % len(_a			)

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

		return result






def 	lowerCamelCase_       (			_a      ,  _a      ,  _a = None			):




		"""simple docstring"""






		key *= -1

		return encrypt(_a      ,  _a      ,  _a			)






def 	lowerCamelCase_       (			_a      ,  _a = None			):




		"""simple docstring"""






		lowerCAmelCase__  :     Optional[Any]       	=   alphabet or ascii_letters

		# To store data on all the combinations
		lowerCAmelCase__  :     Optional[int]       	=   {}

		# Cycle through each combination
		for key in range(1      ,  len(_a			) + 1			):
				# Decrypt the message and store the result in the data
				lowerCAmelCase__  :     Optional[int]       	=   decrypt(_a      ,  _a      ,  _a			)

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

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

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

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

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




