






"""simple docstring"""


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


__SCREAMING_SNAKE_CASE   =   logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE   =   {"""vocab_file""": """vocab.txt"""}

__SCREAMING_SNAKE_CASE   =   {
    """vocab_file""": {
        """YituTech/conv-bert-base""": """https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt""",
        """YituTech/conv-bert-medium-small""": (
            """https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt"""
        ),
        """YituTech/conv-bert-small""": """https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt""",
    }
}

__SCREAMING_SNAKE_CASE   =   {
    """YituTech/conv-bert-base""": 5_12,
    """YituTech/conv-bert-medium-small""": 5_12,
    """YituTech/conv-bert-small""": 5_12,
}


__SCREAMING_SNAKE_CASE   =   {
    """YituTech/conv-bert-base""": {"""do_lower_case""": True},
    """YituTech/conv-bert-medium-small""": {"""do_lower_case""": True},
    """YituTech/conv-bert-small""": {"""do_lower_case""": True},
}




class 						__UpperCamelCase     (     __snake_case						):
					lowercase_    :				Optional[int]      =  VOCAB_FILES_NAMES
					lowercase_    :				Optional[int]      =  PRETRAINED_VOCAB_FILES_MAP
					lowercase_    :				str      =  PRETRAINED_INIT_CONFIGURATION
					lowercase_    :				List[Any]      =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					lowercase_    :				Optional[int]      =  ConvBertTokenizer
					def __init__(							self							:	Any     , UpperCAmelCase							:	Optional[Any]=None     , UpperCAmelCase							:	Optional[int]=None     , UpperCAmelCase							:	Tuple=True     , UpperCAmelCase							:	List[str]="[UNK]"     , UpperCAmelCase							:	Any="[SEP]"     , UpperCAmelCase							:	Optional[int]="[PAD]"     , UpperCAmelCase							:	List[Any]="[CLS]"     , UpperCAmelCase							:	Any="[MASK]"     , UpperCAmelCase							:	List[str]=True     , UpperCAmelCase							:	Any=None     , **UpperCAmelCase							:	List[str]     , )	->       Optional[int]:
											super().__init__(
											    UpperCAmelCase     , tokenizer_file=UpperCAmelCase     , do_lower_case=UpperCAmelCase     , unk_token=UpperCAmelCase     , sep_token=UpperCAmelCase     , pad_token=UpperCAmelCase     , cls_token=UpperCAmelCase     , mask_token=UpperCAmelCase     , tokenize_chinese_chars=UpperCAmelCase     , strip_accents=UpperCAmelCase     , **UpperCAmelCase     , )

											lowerCAmelCase   :int						=			json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
											if (
											    normalizer_state.get('lowercase'     , UpperCAmelCase   ) != do_lower_case
											    or normalizer_state.get('strip_accents'     , UpperCAmelCase   ) != strip_accents
											    or normalizer_state.get('handle_chinese_chars'     , UpperCAmelCase   ) != tokenize_chinese_chars
											):
																	lowerCAmelCase   :Optional[Any]						=			getattr(UpperCAmelCase     , normalizer_state.pop('type'   )   )
																	lowerCAmelCase   :Any						=			do_lower_case
																	lowerCAmelCase   :List[Any]						=			strip_accents
																	lowerCAmelCase   :str						=			tokenize_chinese_chars
																	lowerCAmelCase   :Dict						=			normalizer_class(**UpperCAmelCase   )

											lowerCAmelCase   :Optional[int]						=			do_lower_case
					def        UpperCAmelCase__ (							self							:	Tuple     , UpperCAmelCase							:	int     , UpperCAmelCase							:	Dict=None   )	->       Optional[Any]:
											lowerCAmelCase   :Any						=			[self.cls_token_id] + token_ids_a + [self.sep_token_id]

											if token_ids_a:
																	output += token_ids_a + [self.sep_token_id]

											return output
					def        UpperCAmelCase__ (							self							:	str     , UpperCAmelCase							:	List[int]     , UpperCAmelCase							:	Optional[List[int]] = None   )	->       List[int]:
											lowerCAmelCase   :Optional[Any]						=			[self.sep_token_id]
											lowerCAmelCase   :Dict						=			[self.cls_token_id]
											if token_ids_a is None:
																	return len(cls + token_ids_a + sep   ) * [0]
											return len(cls + token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]
					def        UpperCAmelCase__ (							self							:	Any     , UpperCAmelCase							:	str     , UpperCAmelCase							:	Optional[str] = None   )	->       Tuple[str]:
											lowerCAmelCase   :Union[str, Any]						=			self._tokenizer.model.save(UpperCAmelCase     , name=UpperCAmelCase   )
											return tuple(UpperCAmelCase   )

import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

UpperCamelCase_						:     List[Any]	       =							3



def 		UpperCamelCase     (       _UpperCAmelCase  :   int  )   ->			int:






						'''simple docstring'''

						print("Generating primitive root of p"  )
						while True:
												_lowercase       :	Any           =   random.randrange(3 ,			_UpperCAmelCase  )
												if pow(_UpperCAmelCase ,			2 ,			_UpperCAmelCase  ) == 1:
																		continue
												if pow(_UpperCAmelCase ,			_UpperCAmelCase ,			_UpperCAmelCase  ) == 1:
																		continue
												return g



def 		UpperCamelCase     (       _UpperCAmelCase  :   int  )   ->			tuple[tuple[int, int, int, int], tuple[int, int]]:






						'''simple docstring'''

						print("Generating prime p..."  )
						_lowercase       :	Optional[int]           =   rabin_miller.generate_large_prime(_UpperCAmelCase  )  # select large prime number.
						_lowercase       :	Dict           =   primitive_root(_UpperCAmelCase  )  # one primitive root on modulo p.
						_lowercase       :	Any           =   random.randrange(3 ,			_UpperCAmelCase  )  # private_key -> have to be greater than 2 for safety.
						_lowercase       :	Tuple           =   cryptomath.find_mod_inverse(pow(_UpperCAmelCase ,			_UpperCAmelCase ,			_UpperCAmelCase  ) ,			_UpperCAmelCase  )

						_lowercase       :	List[Any]           =   (key_size, e_a, e_a, p)
						_lowercase       :	Union[str, Any]           =   (key_size, d)

						return public_key, private_key



def 		UpperCamelCase     (       _UpperCAmelCase  :   str ,			_UpperCAmelCase  :   int  )   ->			None:






						'''simple docstring'''

						if os.path.exists(f"""{name}_pubkey.txt"""  ) or os.path.exists(f"""{name}_privkey.txt"""  ):
												print("\nWARNING:"  )
												print(
												    f"""\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"""
												    "Use a different name or delete these files and re-run this program."  )
												sys.exit()

						_lowercase      ,    _lowercase       :	Optional[Any]           =   generate_key(_UpperCAmelCase  )
						print(f"""\nWriting public key to file {name}_pubkey.txt..."""  )
						with open(f"""{name}_pubkey.txt""" ,			"w"  ) as fo:
												fo.write(f"""{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}"""  )

						print(f"""Writing private key to file {name}_privkey.txt..."""  )
						with open(f"""{name}_privkey.txt""" ,			"w"  ) as fo:
												fo.write(f"""{private_key[0]},{private_key[1]}"""  )



def 		UpperCamelCase     (       )   ->			None:






						'''simple docstring'''

						print("Making key files..."  )
						make_key_files("elgamal" ,			2048  )
						print("Key files generation successful"  )


if __name__ == "__main__":
							main()




