



'''simple docstring'''





import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812

def        a_     (							)      ->      None:
  print('Making key files...'       )
  make_key_files('rsa'       ,1024       )
  print('Key files generation successful.'       )

def        a_     (							_lowerCAmelCase       )      ->      tuple[tuple[int, int], tuple[int, int]]:
  print('Generating prime p...'       )
  __lowerCamelCase       :       str           = rabinMiller.generate_large_prime(_lowerCAmelCase       )
  print('Generating prime q...'       )
  __lowerCamelCase       :       Optional[int]           = rabinMiller.generate_large_prime(_lowerCAmelCase       )
  __lowerCamelCase       :       List[str]           = p * q

  print('Generating e that is relatively prime to (p - 1) * (q - 1)...'       )
  while True:
    __lowerCamelCase       :       List[str]           = random.randrange(2 ** (key_size - 1)       ,2 ** (key_size)       )
    if cryptoMath.gcd(_lowerCAmelCase       ,(p - 1) * (q - 1)       ) == 1:
      break

  print('Calculating d that is mod inverse of e...'       )
  __lowerCamelCase       :       Union[str, Any]           = cryptoMath.find_mod_inverse(_lowerCAmelCase       ,(p - 1) * (q - 1)       )

  __lowerCamelCase       :       int           = (n, e)
  __lowerCamelCase       :       str           = (n, d)
  return (public_key, private_key)

def        a_     (							_lowerCAmelCase       ,_lowerCAmelCase       )      ->      None:
  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()

  __lowerCamelCase       ,__lowerCamelCase       :       List[Any]           = generate_key(_lowerCAmelCase       )
  print(F'\nWriting public key to file {name}_pubkey.txt...'       )
  with open(F'{name}_pubkey.txt'       ,'w'       ) as out_file:
    out_file.write(F'{key_size},{public_key[0]},{public_key[1]}'       )

  print(F'Writing private key to file {name}_privkey.txt...'       )
  with open(F'{name}_privkey.txt'       ,'w'       ) as out_file:
    out_file.write(F'{key_size},{private_key[0]},{private_key[1]}'       )


if __name__ == "__main__":
   main()











'''simple docstring'''





import inspect
import warnings
from typing import Any, Dict, Optional, Union

from packaging import version

def        a_     (							*_lowerCAmelCase       ,_lowerCAmelCase = None       ,_lowerCAmelCase=True       ,_lowerCAmelCase=2       )      ->      List[str]:
  from .. import __version__

  __lowerCamelCase       :       Any           = take_from
  __lowerCamelCase       :       Optional[int]           = ()
  if not isinstance(args[0]       ,_lowerCAmelCase       ):
    __lowerCamelCase       :       Optional[Any]           = (args,)

  for attribute, version_name, message in args:
    if version.parse(version.parse(_lowerCAmelCase       ).base_version       ) >= version.parse(_lowerCAmelCase       ):
      raise ValueError(
          F'The deprecation tuple {(attribute, version_name, message)} should be removed since diffusers\''
          F' version {__version__} is >= {version_name}'       )

    __lowerCamelCase       :       Union[str, Any]           = None
    if isinstance(_lowerCAmelCase       ,_lowerCAmelCase       ) and attribute in deprecated_kwargs:
      values += (deprecated_kwargs.pop(_lowerCAmelCase       ),)
      __lowerCamelCase       :       Optional[Any]           = F'The `{attribute}` argument is deprecated and will be removed in version {version_name}.'
    elif hasattr(_lowerCAmelCase       ,_lowerCAmelCase       ):
      values += (getattr(_lowerCAmelCase       ,_lowerCAmelCase       ),)
      __lowerCamelCase       :       List[str]           = F'The `{attribute}` attribute is deprecated and will be removed in version {version_name}.'
    elif deprecated_kwargs is None:
      __lowerCamelCase       :       Optional[Any]           = F'`{attribute}` is deprecated and will be removed in version {version_name}.'

    if warning is not None:
      __lowerCamelCase       :       Optional[int]           = warning + ' ' if standard_warn else ''
      warnings.warn(warning + message       ,_lowerCAmelCase       ,stacklevel=_lowerCAmelCase       )

  if isinstance(_lowerCAmelCase       ,_lowerCAmelCase       ) and len(_lowerCAmelCase       ) > 0:
    __lowerCamelCase       :       Optional[Any]           = inspect.getouterframes(inspect.currentframe()       )[1]
    __lowerCamelCase       :       List[str]           = call_frame.filename
    __lowerCamelCase       :       int           = call_frame.lineno
    __lowerCamelCase       :       Union[str, Any]           = call_frame.function
    __lowerCamelCase       ,__lowerCamelCase       :       Union[str, Any]           = next(iter(deprecated_kwargs.items()       )       )
    raise TypeError(F'{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`'       )

  if len(_lowerCAmelCase       ) == 0:
    return
  elif len(_lowerCAmelCase       ) == 1:
    return values[0]
  return values






