

import os
import random
import sys

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



def   __UpperCAmelCase					(      )     ->	None:

					"""simple docstring"""

					print('''Making key files...'''      )
					make_key_files('''rsa'''						,1_024      )
					print('''Key files generation successful.'''      )



def   __UpperCAmelCase					(      __a :     int      )     ->	tuple[tuple[int, int], tuple[int, int]]:

					"""simple docstring"""

					print('''Generating prime p...'''      )
					_a      :       Union[str, Any]   =						rabinMiller.generate_large_prime(__a      )
					print('''Generating prime q...'''      )
					_a      :       Optional[Any]   =						rabinMiller.generate_large_prime(__a      )
					_a      :       Union[str, Any]   =						p * q

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

					print('''Calculating d that is mod inverse of e...'''      )
					_a      :       Optional[int]   =						cryptoMath.find_mod_inverse(__a						,(p - 1) * (q - 1)      )

					_a      :       Optional[Any]   =						(n, e)
					_a      :       int   =						(n, d)
					return (public_key, private_key)



def   __UpperCAmelCase					(      __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()

					_a ,   _a      :       List[str]   =						generate_key(__a      )
					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()






from __future__ import annotations

import matplotlib.pyplot as plt  # type: ignore
import numpy

# initial triangle of Koch snowflake
a__												=						numpy.array([0, 0])
a__												=						numpy.array([0.5, 0.8660254])
a__												=						numpy.array([1, 0])
a__												=						[VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_1]



def   __UpperCAmelCase					(      __a :     list[numpy.ndarray]						,__a :     int      )     ->	list[numpy.ndarray]:

					"""simple docstring"""

					_a      :       Tuple   =						initial_vectors
					for _ in range(__a      ):
										_a      :       int   =						iteration_step(__a      )
					return vectors



def   __UpperCAmelCase					(      __a :     list[numpy.ndarray]      )     ->	list[numpy.ndarray]:

					"""simple docstring"""

					_a      :       Tuple   =						[]
					for i, start_vector in enumerate(vectors[:-1]      ):
										_a      :       str   =						vectors[i + 1]
										new_vectors.append(__a      )
										_a      :       Optional[int]   =						end_vector - start_vector
										new_vectors.append(start_vector + difference_vector / 3      )
										new_vectors.append(
										    start_vector + difference_vector / 3 + rotate(difference_vector / 3						,60      )      )
										new_vectors.append(start_vector + difference_vector * 2 / 3      )
					new_vectors.append(vectors[-1]      )
					return new_vectors



def   __UpperCAmelCase					(      __a :     numpy.ndarray						,__a :     float      )     ->	numpy.ndarray:

					"""simple docstring"""

					_a      :       Tuple   =						numpy.radians(__a      )
					_a ,   _a      :       List[Any]   =						numpy.cos(__a      ), numpy.sin(__a      )
					_a      :       Dict   =						numpy.array(((c, -s), (s, c))      )
					return numpy.dot(__a						,__a      )



def   __UpperCAmelCase					(      __a :     list[numpy.ndarray]      )     ->	None:

					"""simple docstring"""

					_a      :       str   =						plt.gca()
					axes.set_aspect('''equal'''      )

					# matplotlib.pyplot.plot takes a list of all x-coordinates and a list of all
					# y-coordinates as inputs, which are constructed from the vector-list using
					# zip()
					_a ,   _a      :       Optional[int]   =						zip(*__a      )
					plt.plot(__a						,__a      )
					plt.show()


if __name__ == "__main__":
			import doctest

			doctest.testmod()

			a__												=						iterate(INITIAL_VECTORS, 5)
			plot(processed_vectors)



