






'''simple docstring'''







import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__lowerCAmelCase        =							3


def       __UpperCamelCase					(      lowercase_       :  int   ):
       """simple docstring"""




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


def       __UpperCamelCase					(      lowercase_       :  int   ):
       """simple docstring"""




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

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

       return public_key, private_key


def       __UpperCamelCase					(      lowercase_       :  str   ,       lowercase_       :  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()

       a_						     =			generate_key(lowerCamelCase_   )
       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'   ,       2_048   )
       print('Key files generation successful'   )


if __name__ == "__main__":
  main()









"""simple docstring"""







import requests

def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							str     ,		lowerCamelCase_:							str ):
						"""simple docstring"""






						snake_case   :			List[str]						    = {"Content-Type": "application/json"}
						snake_case   :			int						    = requests.post(lowerCamelCase_     ,		json={"text": message_body}     ,		headers=lowerCamelCase_ )
						if response.status_code != 2_0_0:
												snake_case   :			str						    = (
												    "Request to slack returned an error "
												    f'''{response.status_code}, the response is:\n{response.text}'''
												)
												raise ValueError(lowerCamelCase_ )


if __name__ == "__main__":
			# Set the slack url to the one provided by Slack when you create the webhook at
			# https://my.slack.com/services/new/incoming-webhook/
			send_slack_message('<YOUR MESSAGE BODY>', '<SLACK CHANNEL URL>')



