





import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

snake_case__					:							Union[str, Any]													=     3



def _a				(	lowerCamelCase:   int )	->						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 _a				(	lowerCamelCase:   int )	->						tuple[tuple[int, int, int, int], tuple[int, 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 _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 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 _a				(	)	->						None:







      '''simple docstring'''






      print('''Making key files...''' )
      make_key_files('''elgamal'''					,				20_48 )
      print('''Key files generation successful''' )


if __name__ == "__main__":
       main()












from __future__ import annotations



def _a				(	lowerCamelCase:   list[int | str] )	->						None:







      '''simple docstring'''






      create_state_space_tree(lowerCamelCase					,				[]					,				0					,				[0 for i in range(len(lowerCamelCase ) )] )



def _a				(	lowerCamelCase:   list[int | str]					,				lowerCamelCase:   list[int | str]					,				lowerCamelCase:   int					,				lowerCamelCase:   list[int]					,				)	->						None:







      '''simple docstring'''






      if index == len(lowerCamelCase ):
            print(lowerCamelCase )
            return

      for i in range(len(lowerCamelCase ) ):
            if not index_used[i]:
                  current_sequence.append(sequence[i] )
                  __A          =				True
                  create_state_space_tree(lowerCamelCase					,				lowerCamelCase					,				index + 1					,				lowerCamelCase )
                  current_sequence.pop()
                  __A          =				False
snake_case__					:							list[int | str]													=     [3, 1, 2, 4]
generate_all_permutations(sequence)

snake_case__					:							list[int | str]													=     ["A", "B", "C"]







generate_all_permutations(sequence_a)





