


'''simple docstring'''






import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__A :  List[Any]    							=				3







def     UpperCamelCase_      (   A__ :       int ):
  '''simple docstring'''





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







def     UpperCamelCase_      (   A__ :       int ):
  '''simple docstring'''





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

  lowerCAmelCase_      :				int      =       (key_size, e_a, e_a, p)
  lowerCAmelCase_      :				str      =       (key_size, d)

  return public_key, private_key







def     UpperCamelCase_      (   A__ :       str							,   A__ :       int ):
  '''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()

  lowerCAmelCase_,							lowerCAmelCase_      :				Optional[Any]      =       generate_key(A__ )
  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_      (   ):
  '''simple docstring'''





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


if __name__ == "__main__":
  main()







'''simple docstring'''






from __future__ import annotations







def     UpperCamelCase_      (   A__ :       int | float | str							,   A__ :       int | float | str ):
  '''simple docstring'''





  if nth_term == "":
    return [""]
  lowerCAmelCase_      :				str      =       int(A__ )
  lowerCAmelCase_      :				Tuple      =       int(A__ )
  lowerCAmelCase_      :				list[str]      =       []
  for temp in range(int(A__ ) ):
    series.append(f'1 / {pow(temp + 1							,   int(A__ ) )}' if series else """1""" )
  return series


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  __A :  str    							=				int(input("Enter the last number (nth term) of the P-Series"))
  __A :  Tuple    							=				int(input("Enter the power for  P-Series"))
  print("Formula of P-Series => 1+1/2^p+1/3^p ..... 1/n^p")
  print(p_series(nth_term, power))



