




import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

snake_case_ : Optional[Any]    		=       3


def    A						(__A   :    int       )   ->      int:







     """simple docstring"""


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


def    A						(__A   :    int       )   ->      tuple[tuple[int, int, int, int], tuple[int, int]]:







     """simple docstring"""


     print('''Generating prime p...'''       )
     UpperCAmelCase_          =							rabin_miller.generate_large_prime(__A       )  # select large prime number.
     UpperCAmelCase_          =							primitive_root(__A       )  # one primitive root on modulo p.
     UpperCAmelCase_          =							random.randrange(3   ,				__A       )  # private_key -> have to be greater than 2 for safety.
     UpperCAmelCase_          =							cryptomath.find_mod_inverse(pow(__A   ,				__A   ,				__A       )   ,				__A       )

     UpperCAmelCase_          =							(key_size, e_a, e_a, p)
     UpperCAmelCase_          =							(key_size, d)

     return public_key, private_key


def    A						(__A   :    str   ,				__A   :    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()

     UpperCAmelCase_     ,       UpperCAmelCase_          =							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    A						()   ->      None:







     """simple docstring"""


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


if __name__ == "__main__":
    main()













from __future__ import annotations

from collections.abc import Callable





def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__			,			UpperCamelCase__			,			UpperCamelCase__			,			UpperCamelCase__ = 100			,			)  ->				float:







			'''simple docstring'''

			UpperCAmelCase   		=				x_start
			UpperCAmelCase   		=				fnc(UpperCamelCase__ )
			UpperCAmelCase   		=				0.0
			for _ in range(UpperCamelCase__ ):
						# Approximates small segments of curve as linear and solve
						# for trapezoidal area
						UpperCAmelCase   		=				(x_end - x_start) / steps + xa
						UpperCAmelCase   		=				fnc(UpperCamelCase__ )
						area += abs(fxa + fxa ) * (xa - xa) / 2
						# Increment step
						UpperCAmelCase   		=				xa
						UpperCAmelCase   		=				fxa
			return area


if __name__ == "__main__":





				def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__ )  ->				str:







							'''simple docstring'''

							return x**3 + x**2

				print("f(x) = x^3 + x^2")
				print("The area between the curve, x = -5, x = 5 and the x axis is:")
				__A				:    List[Any]       =   10
				while i <= 100_000:
								print(F'with {i} steps: {trapezoidal_area(f, -5, 5, i)}')
								i *= 10



