
"""simple docstring"""




import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

A__ :       str				= 3




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



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




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



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

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

  return public_key, private_key




def 			_lowerCAmelCase		(		_UpperCamelCase			,					_UpperCamelCase    ):






  """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:      int   			=  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		(		):






  """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
import importlib
from pathlib import Path


# Test all the extensions added in the setup
A__ :       Optional[int]				= [
    'kernels/rwkv/wkv_cuda.cu',
    'kernels/rwkv/wkv_op.cpp',
    'kernels/deformable_detr/ms_deform_attn.h',
    'kernels/deformable_detr/cuda/ms_deform_im2col_cuda.cuh',
    'models/graphormer/algos_graphormer.pyx',
]




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



  for file in FILES_TO_FIND:
    if not (transformers_path / file).exists():
      return False
  return True


if __name__ == "__main__":
  A__ :       List[Any]				= argparse.ArgumentParser()
  parser.add_argument('--check_lib', action='store_true', help='Whether to check the build or the actual package.')
  A__ :       Optional[int]				= parser.parse_args()
  if args.check_lib:
    A__ :       Union[str, Any]				= importlib.import_module('transformers')
    A__ :       Optional[Any]				= Path(transformers_module.__file__).parent
  else:
    A__ :       str				= Path.cwd() / 'build/lib/transformers'
  if not test_custom_files_are_present(transformers_path):
    raise ValueError('The built release does not contain the custom files. Fix this before going further!')
