






import string

import numpy







def 	_UpperCamelCase   (    UpperCamelCase_       :					List[str]    ,       UpperCamelCase_       :					Any		)  ->   int:

						"""simple docstring"""



						return b if a == 0 else greatest_common_divisor(b % a    ,       UpperCamelCase_		)

class     __SCREAMING_SNAKE_CASE					:
						_SCREAMING_SNAKE_CASE	:       Any   =					string.ascii_uppercase + string.digits
						# This cipher takes alphanumerics into account
						# i.e. a total of 36 characters

						# take x and return x % len(key_string)
						_SCREAMING_SNAKE_CASE	:       Optional[Any]   =					numpy.vectorize(lambda __lowercase: x % 36)

						_SCREAMING_SNAKE_CASE	:       Dict   =					numpy.vectorize(SCREAMING_SNAKE_CASE__)






						def __init__(	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						self.modulus(snake_case__   )  # mod36 calc's on the encrypt key
												self.check_determinant()  # validate the determinant of the encryption key
												lowerCAmelCase__    						=						encrypt_key.shape[0]






						def       UpperCamelCase__      (	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												return self.key_string.index(snake_case__   )






						def       UpperCamelCase__      (	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												return self.key_string[round(snake_case__   )]






						def       UpperCamelCase__      (	self   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						round(numpy.linalg.det(self.encrypt_key   )   )

												if det < 0:
																		lowerCAmelCase__    						=						det % len(self.key_string   )

												lowerCAmelCase__    						=						len(self.key_string   )
												if greatest_common_divisor(snake_case__     ,						len(self.key_string   )   ) != 1:
																		lowerCAmelCase__    						=						(
																		    F"determinant modular {req_l} of encryption key({det}) "
																		    F"is not co prime w.r.t {req_l}.\nTry another key."
																		)
																		raise ValueError(snake_case__   )






						def       UpperCamelCase__      (	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						[char for char in text.upper() if char in self.key_string]

												lowerCAmelCase__    						=						chars[-1]
												while len(snake_case__   ) % self.break_key != 0:
																		chars.append(snake_case__   )

												return "".join(snake_case__   )






						def       UpperCamelCase__      (	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						self.process_text(text.upper()   )
												lowerCAmelCase__    						=						""

												for i in range(0     ,						len(snake_case__   ) - self.break_key + 1     ,						self.break_key   ):
																		lowerCAmelCase__    						=						text[i : i + self.break_key]
																		lowerCAmelCase__    						=						[self.replace_letters(snake_case__   ) for char in batch]
																		lowerCAmelCase__    						=						numpy.array([vec]   ).T
																		lowerCAmelCase__    						=						self.modulus(self.encrypt_key.dot(snake_case__   )   ).T.tolist()[
																		    0
																		]
																		lowerCAmelCase__    						=						"".join(
																		    self.replace_digits(snake_case__   ) for num in batch_encrypted   )
																		encrypted += encrypted_batch

												return encrypted






						def       UpperCamelCase__      (	self   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						round(numpy.linalg.det(self.encrypt_key   )   )

												if det < 0:
																		lowerCAmelCase__    						=						det % len(self.key_string   )
												lowerCAmelCase__    						=						None
												for i in range(len(self.key_string   )   ):
																		if (det * i) % len(self.key_string   ) == 1:
																								lowerCAmelCase__    						=						i
																								break

												lowerCAmelCase__    						=						(
												    det_inv
												    * numpy.linalg.det(self.encrypt_key   )
												    * numpy.linalg.inv(self.encrypt_key   )
												)

												return self.to_int(self.modulus(snake_case__   )   )







						def       UpperCamelCase__      (	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						self.make_decrypt_key()
												lowerCAmelCase__    						=						self.process_text(text.upper()   )
												lowerCAmelCase__    						=						""

												for i in range(0     ,						len(snake_case__   ) - self.break_key + 1     ,						self.break_key   ):
																		lowerCAmelCase__    						=						text[i : i + self.break_key]
																		lowerCAmelCase__    						=						[self.replace_letters(snake_case__   ) for char in batch]
																		lowerCAmelCase__    						=						numpy.array([vec]   ).T
																		lowerCAmelCase__    						=						self.modulus(decrypt_key.dot(snake_case__   )   ).T.tolist()[0]
																		lowerCAmelCase__    						=						"".join(
																		    self.replace_digits(snake_case__   ) for num in batch_decrypted   )
																		decrypted += decrypted_batch

												return decrypted







def 	_UpperCamelCase   (    )  ->   None:

						"""simple docstring"""



						lowerCAmelCase__    						=						int(input('Enter the order of the encryption key: '		)		)
						lowerCAmelCase__    						=						[]

						print('Enter each row of the encryption key with space separated integers'		)
						for _ in range(UpperCamelCase_		):
												lowerCAmelCase__    						=						[int(UpperCamelCase_		) for x in input().split()]
												hill_matrix.append(UpperCamelCase_		)

						lowerCAmelCase__    						=						HillCipher(numpy.array(UpperCamelCase_		)		)

						print('Would you like to encrypt or decrypt some text? (1 or 2)'		)
						lowerCAmelCase__    						=						input('\n1. Encrypt\n2. Decrypt\n'		)
						if option == "1":
												lowerCAmelCase__    						=						input('What text would you like to encrypt?: '		)
												print('Your encrypted text is:'		)
												print(hc.encrypt(UpperCamelCase_		)		)
						elif option == "2":
												lowerCAmelCase__    						=						input('What text would you like to decrypt?: '		)
												print('Your decrypted text is:'		)
												print(hc.decrypt(UpperCamelCase_		)		)


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					main()













import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if TYPE_CHECKING:
					from transformers.pipelines.conversational import Conversation


__snake_case    :    Any         =     logging.get_logger(__name__)

__snake_case    :    Tuple         =     {"""tokenizer_file""": """tokenizer.json"""}

__snake_case    :    str         =     {
    """tokenizer_file""": {
        """bigscience/tokenizer""": """https://huggingface.co/bigscience/tokenizer/blob/main/tokenizer.json""",
        """bigscience/bloom-560m""": """https://huggingface.co/bigscience/bloom-560m/blob/main/tokenizer.json""",
        """bigscience/bloom-1b1""": """https://huggingface.co/bigscience/bloom-1b1/blob/main/tokenizer.json""",
        """bigscience/bloom-1b7""": """https://huggingface.co/bigscience/bloom-1b7/blob/main/tokenizer.json""",
        """bigscience/bloom-3b""": """https://huggingface.co/bigscience/bloom-3b/blob/main/tokenizer.json""",
        """bigscience/bloom-7b1""": """https://huggingface.co/bigscience/bloom-7b1/blob/main/tokenizer.json""",
        """bigscience/bloom""": """https://huggingface.co/bigscience/bloom/blob/main/tokenizer.json""",
    },
}


class     __SCREAMING_SNAKE_CASE					(   __lowercase):
						_SCREAMING_SNAKE_CASE	:       Dict   =					VOCAB_FILES_NAMES
						_SCREAMING_SNAKE_CASE	:       Union[str, Any]   =					PRETRAINED_VOCAB_FILES_MAP
						_SCREAMING_SNAKE_CASE	:       Union[str, Any]   =					['''input_ids''', '''attention_mask''']
						_SCREAMING_SNAKE_CASE	:       Union[str, Any]   =					None






						def __init__(	self     ,						_UpperCamelCase=None     ,						_UpperCamelCase=None     ,						_UpperCamelCase=None     ,						_UpperCamelCase="<unk>"     ,						_UpperCamelCase="<s>"     ,						_UpperCamelCase="</s>"     ,						_UpperCamelCase="<pad>"     ,						_UpperCamelCase=False     ,						_UpperCamelCase=False     ,						**_UpperCamelCase     ,						):






												"""simple docstring"""
												super().__init__(
												    _UpperCamelCase     ,						_UpperCamelCase     ,						tokenizer_file=_UpperCamelCase     ,						unk_token=_UpperCamelCase     ,						bos_token=_UpperCamelCase     ,						eos_token=_UpperCamelCase     ,						pad_token=_UpperCamelCase     ,						add_prefix_space=_UpperCamelCase     ,						clean_up_tokenization_spaces=_UpperCamelCase     ,						**_UpperCamelCase     ,						)
												lowerCAmelCase__    						=						json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()   )
												if pre_tok_state.get('add_prefix_space'     ,						_UpperCamelCase   ) != add_prefix_space:
																		lowerCAmelCase__    						=						getattr(_UpperCamelCase     ,						pre_tok_state.pop('type'   )   )
																		lowerCAmelCase__    						=						add_prefix_space
																		lowerCAmelCase__    						=						pre_tok_class(**_UpperCamelCase   )

												lowerCAmelCase__    						=						add_prefix_space






						def       UpperCamelCase__      (	self     ,						*_UpperCamelCase     ,						**_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						kwargs.get('is_split_into_words'     ,						_UpperCamelCase   )
												if not (self.add_prefix_space or not is_split_into_words):
																		raise Exception(
																		    F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"
																		    ' pretokenized inputs.'   )

												return super()._batch_encode_plus(*_UpperCamelCase     ,						**_UpperCamelCase   )






						def       UpperCamelCase__      (	self     ,						*_UpperCamelCase     ,						**_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						kwargs.get('is_split_into_words'     ,						_UpperCamelCase   )

												if not (self.add_prefix_space or not is_split_into_words):
																		raise Exception(
																		    F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"
																		    ' pretokenized inputs.'   )

												return super()._encode_plus(*_UpperCamelCase     ,						**_UpperCamelCase   )






						def       UpperCamelCase__      (	self     ,						_UpperCamelCase     ,						_UpperCamelCase = None   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						self._tokenizer.model.save(_UpperCamelCase     ,						name=_UpperCamelCase   )
												return tuple(_UpperCamelCase   )







						def       UpperCamelCase__      (	self     ,						_UpperCamelCase   ):






												"""simple docstring"""
												lowerCAmelCase__    						=						[]
												for is_user, text in conversation.iter_texts():
																		input_ids.extend(self.encode(_UpperCamelCase     ,						add_special_tokens=_UpperCamelCase   ) + [self.eos_token_id]   )

												if len(_UpperCamelCase   ) > self.model_max_length:
																		lowerCAmelCase__    						=						input_ids[-self.model_max_length :]
												return input_ids





