





import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

lowerCAmelCase_        =							3






def 	lowerCamelCase_		(							_UpperCamelCase					)						->		int:






				"""simple docstring"""


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






def 	lowerCamelCase_		(							_UpperCamelCase					)						->		tuple[tuple[int, int, int, int], tuple[int, int]]:






				"""simple docstring"""


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

				snake_case_		:       Dict           =    (key_size, e_a, e_a, p)
				snake_case_		:       Any           =    (key_size, d)

				return public_key, private_key






def 	lowerCamelCase_		(							_UpperCamelCase					,							_UpperCamelCase					)						->		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()

				snake_case_     ,				snake_case_		:       str           =    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 	lowerCamelCase_		(							)						->		None:






				"""simple docstring"""


				print('''Making key files...'''					)
				make_key_files('''elgamal'''					,							2_048					)
				print('''Key files generation successful'''					)


if __name__ == "__main__":
	main()


"""simple docstring"""




import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()




def 			_lowerCAmelCase		(		_UpperCamelCase			,					_UpperCamelCase			,					_UpperCamelCase			,					_UpperCamelCase    ):






  """simple docstring"""



  _lowercase:      int   			=  BigBirdConfig.from_json_file(_UpperCamelCase    )
  print(f'''Building PyTorch model from configuration: {config}'''    )

  if is_trivia_qa:
    _lowercase:      Union[str, Any]   			=  BigBirdForQuestionAnswering(_UpperCamelCase    )
  else:
    _lowercase:      Dict   			=  BigBirdForPreTraining(_UpperCamelCase    )

  # Load weights from tf checkpoint
  load_tf_weights_in_big_bird(_UpperCamelCase			,					_UpperCamelCase			,					is_trivia_qa=_UpperCamelCase    )

  # Save pytorch-model
  print(f'''Save PyTorch model to {pytorch_dump_path}'''    )
  model.save_pretrained(_UpperCamelCase    )


if __name__ == "__main__":
  A__ :       List[Any]				= argparse.ArgumentParser()
  # Required parameters
  parser.add_argument(
      '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
  )
  parser.add_argument(
      '--big_bird_config_file',
      default=None,
      type=str,
      required=True,
      help=(
          'The config json file corresponding to the pre-trained BERT model. \n'
          'This specifies the model architecture.'
      ),
  )
  parser.add_argument(
      '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
  )
  parser.add_argument(
      '--is_trivia_qa', action='store_true', help='Whether to convert a model with a trivia_qa head.'
  )
  A__ :       Optional[Any]				= parser.parse_args()
  convert_tf_checkpoint_to_pytorch(
      args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
  )
