


'''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:




     '''simple docstring'''



     print('Making key files...'						)
     make_key_files('rsa'			,  10_24						)
     print('Key files generation successful.'						)






def 		_A			(lowerCAmelCase__					:int						)				->					tuple[tuple[int, int], tuple[int, int]]:




     '''simple docstring'''



     print('Generating prime p...'						)
     _a      =							rabinMiller.generate_large_prime(lowerCAmelCase__						)
     print('Generating prime q...'						)
     _a      =							rabinMiller.generate_large_prime(lowerCAmelCase__						)
     _a      =							p * q

     print('Generating e that is relatively prime to (p - 1) * (q - 1)...'						)
     while True:
          _a      =							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...'						)
     _a      =							cryptoMath.find_mod_inverse(lowerCAmelCase__			,  (p - 1) * (q - 1)						)

     _a      =							(n, e)
     _a      =							(n, d)
     return (public_key, private_key)






def 		_A			(lowerCAmelCase__					:str			,  lowerCAmelCase__					: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      =							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 colorsys

from PIL import Image  # type: ignore






def 		_A			(lowerCAmelCase__					:float			,  lowerCAmelCase__					:float			,  lowerCAmelCase__					:int						)				->					float:




     '''simple docstring'''



     _a      =							x
     _a      =							y
     for step in range(lowerCAmelCase__						):  # noqa: B007
          _a      =							a * a - b * b + x
          _a      =							2 * a * b + y
          _a      =							a_new

          # divergence happens for all complex number with an absolute value
          # greater than 4
          if a * a + b * b > 4:
               break
     return step / (max_step - 1)






def 		_A			(lowerCAmelCase__					:float						)				->					tuple:




     '''simple docstring'''



     if distance == 1:
          return (0, 0, 0)
     else:
          return (2_55, 2_55, 2_55)






def 		_A			(lowerCAmelCase__					:float						)				->					tuple:




     '''simple docstring'''



     if distance == 1:
          return (0, 0, 0)
     else:
          return tuple(round(i * 2_55						) for i in colorsys.hsv_to_rgb(lowerCAmelCase__			,  1			,  1						)						)






def 		_A			(lowerCAmelCase__					:int = 8_00			,  lowerCAmelCase__					:int = 6_00			,  lowerCAmelCase__					:float = -0.6			,  lowerCAmelCase__					:float = 0			,  lowerCAmelCase__					:float = 3.2			,  lowerCAmelCase__					:int = 50			,  lowerCAmelCase__					:bool = True			,  )				->					Image.Image:




     '''simple docstring'''



     _a      =							Image.new('RGB'			,  (image_width, image_height)						)
     _a      =							img.load()

     # loop through the image-coordinates
     for image_x in range(lowerCAmelCase__						):
          for image_y in range(lowerCAmelCase__						):
               # determine the figure-coordinates based on the image-coordinates
               _a      =							figure_width / image_width * image_height
               _a      =							figure_center_x + (image_x / image_width - 0.5) * figure_width
               _a      =							figure_center_y + (image_y / image_height - 0.5) * figure_height

               _a      =							get_distance(lowerCAmelCase__			,  lowerCAmelCase__			,  lowerCAmelCase__						)

               # color the corresponding pixel based on the selected coloring-function
               if use_distance_color_coding:
                    _a      =							get_color_coded_rgb(lowerCAmelCase__						)
               else:
                    _a      =							get_black_and_white_rgb(lowerCAmelCase__						)

     return img


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 # colored version, full figure
 a_   :      Optional[Any]				    =      get_image()

 # uncomment for colored version, different section, zoomed in
 # img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
 # figure_width = 0.8)

 # uncomment for black and white version, full figure
 # img = get_image(use_distance_color_coding = False)

 # uncomment to save the image
 # img.save("mandelbrot.png")

 img.show()

