






import json
import os
from functools import lru_cache
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import numpy as np
import regex as re

from ...utils import is_tf_available, is_torch_available, logging


if TYPE_CHECKING:
						if is_torch_available():
												import torch
						if is_tf_available():
												import tensorflow as tf

from ...tokenization_utils import AddedToken, PreTrainedTokenizer


__lowerCamelCase						= logging.get_logger(__name__)

__lowerCamelCase						= {
    'vocab_file': 'vocab.json',
    'merges_file': 'merges.txt',
}

__lowerCamelCase						= {
    'vocab_file': {
        'Salesforce/codegen-350M-mono': 'https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/vocab.json',
    },
    'merges_file': {
        'Salesforce/codegen-350M-mono': 'https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/merges.txt',
    },
}

__lowerCamelCase						= {
    'Salesforce/codegen-350M-mono': 2_048,
}






@lru_cache()
def    UpperCamelCase__  (   )     ->		List[str]:







							"""simple docstring"""





							_a  :    Any			=						(
							    list(range(ord('''!'''     )    ,	ord('''~'''     ) + 1     )     ) + list(range(ord('''¡'''     )    ,	ord('''¬'''     ) + 1     )     ) + list(range(ord('''®'''     )    ,	ord('''ÿ'''     ) + 1     )     )
							)
							_a  :    List[str]			=						bs[:]
							_a  :    Any			=						0
							for b in range(2**8     ):
														if b not in bs:
																					bs.append(_SCREAMING_SNAKE_CASE     )
																					cs.append(2**8 + n     )
																					n += 1
							_a  :    List[Any]			=						[chr(_SCREAMING_SNAKE_CASE     ) for n in cs]
							return dict(zip(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE     )     )






def    UpperCamelCase__  (   UpperCAmelCase     )     ->		Union[str, Any]:







							"""simple docstring"""





							_a  :    List[Any]			=						set()
							_a  :    Tuple			=						word[0]
							for char in word[1:]:
														pairs.add((prev_char, char)     )
														_a  :    Union[str, Any]			=						char
							return pairs







class      UpperCamelCase_							(				UpperCamelCase       ):
						lowercase									=  VOCAB_FILES_NAMES
						lowercase									=  PRETRAINED_VOCAB_FILES_MAP
						lowercase									=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						lowercase									=  ["""input_ids""", """attention_mask"""]




						def __init__(    self		,	lowercase		,	lowercase		,	lowercase="replace"		,	lowercase="<|endoftext|>"		,	lowercase="<|endoftext|>"		,	lowercase="<|endoftext|>"		,	lowercase=None		,	lowercase=False		,	lowercase=False		,	**lowercase		,	)			->						Union[str, Any]:
													_a  :    Dict			=						AddedToken(_lowerCamelCase		,	lstrip=_lowerCamelCase		,	rstrip=_lowerCamelCase       ) if isinstance(_lowerCamelCase		,	_lowerCamelCase       ) else bos_token
													_a  :    List[Any]			=						AddedToken(_lowerCamelCase		,	lstrip=_lowerCamelCase		,	rstrip=_lowerCamelCase       ) if isinstance(_lowerCamelCase		,	_lowerCamelCase       ) else eos_token
													_a  :    List[str]			=						AddedToken(_lowerCamelCase		,	lstrip=_lowerCamelCase		,	rstrip=_lowerCamelCase       ) if isinstance(_lowerCamelCase		,	_lowerCamelCase       ) else unk_token
													_a  :    str			=						AddedToken(_lowerCamelCase		,	lstrip=_lowerCamelCase		,	rstrip=_lowerCamelCase       ) if isinstance(_lowerCamelCase		,	_lowerCamelCase       ) else pad_token
													super().__init__(
													    errors=_lowerCamelCase		,	unk_token=_lowerCamelCase		,	bos_token=_lowerCamelCase		,	eos_token=_lowerCamelCase		,	pad_token=_lowerCamelCase		,	add_prefix_space=_lowerCamelCase		,	add_bos_token=_lowerCamelCase		,	**_lowerCamelCase		,	)
													_a  :    List[str]			=						add_bos_token

													with open(_lowerCamelCase		,	encoding='''utf-8'''       ) as vocab_handle:
																				_a  :    Optional[int]			=						json.load(_lowerCamelCase       )
													_a  :    Optional[Any]			=						{v: k for k, v in self.encoder.items()}
													_a  :    Optional[int]			=						errors  # how to handle errors in decoding
													_a  :    List[str]			=						bytes_to_unicode()
													_a  :    List[str]			=						{v: k for k, v in self.byte_encoder.items()}
													with open(_lowerCamelCase		,	encoding='''utf-8'''       ) as merges_handle:
																				_a  :    List[str]			=						merges_handle.read().split('''\n'''       )[1:-1]
													_a  :    List[Any]			=						[tuple(merge.split()       ) for merge in bpe_merges]
													_a  :    Optional[Any]			=						dict(zip(_lowerCamelCase		,	range(len(_lowerCamelCase       )       )       )       )
													_a  :    List[str]			=						{}
													_a  :    List[str]			=						add_prefix_space

													# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
													_a  :    Tuple			=						re.compile(r'''\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'''       )




						@property
						def      snake_case__(    self       )			->						Any:
													return len(self.encoder       )




						def      snake_case__(    self       )			->						str:
													return dict(self.encoder		,	**self.added_tokens_encoder       )




						def      snake_case__(    self		,	lowercase       )			->						Optional[int]:
													if token in self.cache:
																				return self.cache[token]
													_a  :    Optional[int]			=						tuple(_lowerCamelCase       )
													_a  :    Any			=						get_pairs(_lowerCamelCase       )

													if not pairs:
																				return token

													while True:
																				_a  :    Any			=						min(_lowerCamelCase		,	key=lambda lowercase       : self.bpe_ranks.get(_lowerCamelCase		,	float('''inf'''       )       )       )
																				if bigram not in self.bpe_ranks:
																											break
																				_a  :    List[str]			=						bigram
																				_a  :    Dict			=						[]
																				_a  :    str			=						0
																				while i < len(_lowerCamelCase       ):
																											try:
																																		_a  :    str			=						word.index(_lowerCamelCase		,	_lowerCamelCase       )
																											except ValueError:
																																		new_word.extend(word[i:]       )
																																		break
																											else:
																																		new_word.extend(word[i:j]       )
																																		_a  :    Dict			=						j

																											if word[i] == first and i < len(_lowerCamelCase       ) - 1 and word[i + 1] == second:
																																		new_word.append(first + second       )
																																		i += 2
																											else:
																																		new_word.append(word[i]       )
																																		i += 1
																				_a  :    List[str]			=						tuple(_lowerCamelCase       )
																				_a  :    str			=						new_word
																				if len(_lowerCamelCase       ) == 1:
																											break
																				else:
																											_a  :    str			=						get_pairs(_lowerCamelCase       )
													_a  :    Optional[Any]			=						" ".join(_lowerCamelCase       )
													_a  :    Dict			=						word
													return word




						def      snake_case__(    self		,	lowercase		,	lowercase=None       )			->						Tuple:
													if self.add_bos_token:
																				_a  :    Optional[int]			=						[self.bos_token_id]
													else:
																				_a  :    Tuple			=						[]

													_a  :    Tuple			=						bos_token_ids + token_ids_a

													if token_ids_a is None:
																				return output

													return output + bos_token_ids + token_ids_a




						def      snake_case__(    self		,	lowercase       )			->						Tuple:
													_a  :    int			=						[]
													for token in re.findall(self.pat		,	_lowerCamelCase       ):
																				_a  :    List[Any]			=						"".join(
																				    self.byte_encoder[b] for b in token.encode('''utf-8'''       )       )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
																				bpe_tokens.extend(bpe_token for bpe_token in self.bpe(_lowerCamelCase       ).split(''' '''       )       )
													return bpe_tokens




						def      snake_case__(    self		,	lowercase       )			->						Union[str, Any]:
													return self.encoder.get(_lowerCamelCase		,	self.encoder.get(self.unk_token       )       )




						def      snake_case__(    self		,	lowercase       )			->						Optional[int]:
													return self.decoder.get(_lowerCamelCase       )




						def      snake_case__(    self		,	lowercase       )			->						Any:
													_a  :    str			=						"".join(_lowerCamelCase       )
													_a  :    Dict			=						bytearray([self.byte_decoder[c] for c in text]       ).decode('''utf-8'''		,	errors=self.errors       )
													return text




						def      snake_case__(    self		,	lowercase		,	lowercase = None       )			->						Optional[int]:
													if not os.path.isdir(_lowerCamelCase       ):
																				logger.error(F'Vocabulary path ({save_directory}) should be a directory'       )
																				return
													_a  :    int			=						os.path.join(
													    _lowerCamelCase		,	(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']       )
													_a  :    Tuple			=						os.path.join(
													    _lowerCamelCase		,	(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''merges_file''']       )

													with open(_lowerCamelCase		,	'''w'''		,	encoding='''utf-8'''       ) as f:
																				f.write(json.dumps(self.encoder		,	indent=2		,	sort_keys=_lowerCamelCase		,	ensure_ascii=_lowerCamelCase       ) + '''\n'''       )

													_a  :    str			=						0
													with open(_lowerCamelCase		,	'''w'''		,	encoding='''utf-8'''       ) as writer:
																				writer.write('''#version: 0.2\n'''       )
																				for bpe_tokens, token_index in sorted(self.bpe_ranks.items()		,	key=lambda lowercase       : kv[1]       ):
																											if index != token_index:
																																		logger.warning(
																																		    F'Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'
																																		    ''' Please check that the tokenizer is not corrupted!'''       )
																																		_a  :    Tuple			=						token_index
																											writer.write(''' '''.join(_lowerCamelCase       ) + '''\n'''       )
																											index += 1

													return vocab_file, merge_file




						def      snake_case__(    self		,	lowercase		,	lowercase=False		,	**lowercase       )			->						Optional[int]:
													_a  :    int			=						kwargs.pop('''add_prefix_space'''		,	self.add_prefix_space       )
													if is_split_into_words or add_prefix_space:
																				_a  :    Dict			=						" " + text
													return (text, kwargs)




						def      snake_case__(    self		,	lowercase		,	lowercase = False		,	lowercase = None		,	lowercase = None		,	**lowercase		,	)			->						int:
													_a  :    Optional[Any]			=						super()._decode(
													    token_ids=_lowerCamelCase		,	skip_special_tokens=_lowerCamelCase		,	clean_up_tokenization_spaces=_lowerCamelCase		,	**_lowerCamelCase		,	)

													if truncate_before_pattern is not None and len(_lowerCamelCase       ) > 0:
																				_a  :    Optional[Any]			=						self.truncate(_lowerCamelCase		,	_lowerCamelCase       )

													return decoded_text







						def      snake_case__(    self		,	lowercase		,	lowercase       )			->						Optional[int]:
													def find_re(lowercase		,	lowercase		,	lowercase       ):
																				_a  :    Any			=						pattern.search(_lowerCamelCase		,	_lowerCamelCase       )
																				return m.start() if m else -1

													_a  :    Union[str, Any]			=						[re.compile(_lowerCamelCase		,	re.MULTILINE       ) for pattern in truncate_before_pattern]

													_a  :    Tuple			=						list(re.finditer('''^print'''		,	_lowerCamelCase		,	re.MULTILINE       )       )

													if len(_lowerCamelCase       ) > 1:
																				_a  :    int			=						completion[: prints[1].start()]

													_a  :    Optional[Any]			=						list(re.finditer('''^def'''		,	_lowerCamelCase		,	re.MULTILINE       )       )

													if len(_lowerCamelCase       ) > 1:
																				_a  :    Optional[Any]			=						completion[: defs[1].start()]

													_a  :    List[Any]			=						0

													_a  :    Optional[Any]			=						[
													    pos for pos in [find_re(_lowerCamelCase		,	_lowerCamelCase		,	_lowerCamelCase       ) for terminal in terminals] if pos != -1
													]

													if len(_lowerCamelCase       ) > 0:
																				return completion[: min(_lowerCamelCase       )]
													else:
																				return completion

from __future__ import annotations

from string import ascii_letters




def 		lowerCAmelCase_     (     _SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE = None  )   ->      str:

							"""simple docstring"""






							_UpperCAmelCase  :			List[Any]	       =		alphabet or ascii_letters

							# The final result string
							_UpperCAmelCase  :			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
																					_UpperCAmelCase  :			Any	       =		(alpha.index(_SCREAMING_SNAKE_CASE  ) + key) % len(_SCREAMING_SNAKE_CASE  )

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

							return result




def 		lowerCAmelCase_     (     _SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE = None  )   ->      str:

							"""simple docstring"""






							key *= -1

							return encrypt(_SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE  )




def 		lowerCAmelCase_     (     _SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE = None  )   ->      dict[int, str]:

							"""simple docstring"""






							_UpperCAmelCase  :			Any	       =		alphabet or ascii_letters

							# To store data on all the combinations
							_UpperCAmelCase  :			Dict	       =		{}

							# Cycle through each combination
							for key in range(1      ,	len(_SCREAMING_SNAKE_CASE  ) + 1  ):
														# Decrypt the message and store the result in the data
														_UpperCAmelCase  :			Union[str, Any]	       =		decrypt(_SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE      ,	_SCREAMING_SNAKE_CASE  )

							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
								__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




