


import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812
def 				__lowerCamelCase						( ):




      """simple docstring"""





      print('''Making key files...'''						)
      make_key_files('''rsa''' ,  1024						)
      print('''Key files generation successful.'''						)
def 				__lowerCamelCase						( UpperCAmelCase_						:		int						):




      """simple docstring"""





      print('''Generating prime p...'''						)
      a						:Dict 							=       rabinMiller.generate_large_prime(UpperCAmelCase_						)
      print('''Generating prime q...'''						)
      a						:Optional[Any] 							=       rabinMiller.generate_large_prime(UpperCAmelCase_						)
      a						:int 							=       p * q

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

      print('''Calculating d that is mod inverse of e...'''						)
      a						:Union[str, Any] 							=       cryptoMath.find_mod_inverse(UpperCAmelCase_ ,  (p - 1) * (q - 1)						)

      a						:Tuple 							=       (n, e)
      a						:Optional[int] 							=       (n, d)
      return (public_key, private_key)
def 				__lowerCamelCase						( UpperCAmelCase_						:		str ,  UpperCAmelCase_						:		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							,				a						:List[str] 							=       generate_key(UpperCAmelCase_						)
      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()







def 						UpperCAmelCase			(	a_						)		->	list:







				"""simple docstring"""



				if len(a_						) <= 1:
								return [tuple(a_						)]

				__A   			= []

				def generate(a_		,   a_						):
								if k == 1:
												res.append(tuple(arr[:]						)						)
												return

								generate(k - 1		,   a_						)

								for i in range(k - 1						):
												if k % 2 == 0:  # k is even
																__A			,							__A   			= arr[k - 1], arr[i]
												else:  # k is odd
																__A			,							__A   			= arr[k - 1], arr[0]
												generate(k - 1		,   a_						)

				generate(len(a_						)		,   a_						)
				return res


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE							:int							 =				input('Enter numbers separated by a comma:\n').strip()
					SCREAMING_SNAKE_CASE							:Dict							 =				[int(item) for item in user_input.split(',')]
					print(heaps(arr))
