


import os
import random
import sys

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







def        lowerCAmelCase_  (      ):
							print("Making key files..."			)
							make_key_files("rsa"							,			1_0_2_4			)
							print("Key files generation successful."			)







def        lowerCAmelCase_  (      __lowerCamelCase			):
							print("Generating prime p..."			)
							__snake_case	:    Union[str, Any]											=     rabinMiller.generate_large_prime(__lowerCamelCase			)
							print("Generating prime q..."			)
							__snake_case	:    Optional[Any]											=     rabinMiller.generate_large_prime(__lowerCamelCase			)
							__snake_case	:    Optional[Any]											=     p * q

							print("Generating e that is relatively prime to (p - 1) * (q - 1)..."			)
							while True:
														__snake_case	:    Tuple											=     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..."			)
							__snake_case	:    Optional[Any]											=     cryptoMath.find_mod_inverse(__lowerCamelCase							,			(p - 1) * (q - 1)			)

							__snake_case	:    Any											=     (n, e)
							__snake_case	:    Any											=     (n, d)
							return (public_key, private_key)







def        lowerCAmelCase_  (      __lowerCamelCase							,			__lowerCamelCase			):
							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	:    Tuple											=     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()





import math







def        lowerCAmelCase_  (      __lowerCamelCase							,			__lowerCamelCase			):

							if initial_intensity < 0:
														raise ValueError("The value of intensity cannot be negative"			)
														# handling of negative values of initial intensity
							if angle < 0 or angle > 3_6_0:
														raise ValueError("In Malus Law, the angle is in the range 0-360 degrees"			)
														# handling of values out of allowed range
							return initial_intensity * (math.cos(math.radians(__lowerCamelCase			)			) ** 2)


if __name__ == "__main__":
			import doctest

			doctest.testmod(name="malus_law")

