"""simple docstring"""







__SCREAMING_SNAKE_CASE								=[0, 2, 4, 6, 8]
__SCREAMING_SNAKE_CASE								=[1, 3, 5, 7, 9]



def     lowercase__( __SCREAMING_SNAKE_CASE							:  int  ,    __SCREAMING_SNAKE_CASE							:  int  ,    __SCREAMING_SNAKE_CASE							:  list[int]  ,    __SCREAMING_SNAKE_CASE							:  int   ):
     if remaining_length == 0:
          if digits[0] == 0 or digits[-1] == 0:
               return 0

          for i in range(length // 2 - 1  ,    -1  ,    -1   ):
               remainder += digits[i] + digits[length - i - 1]

               if remainder % 2 == 0:
                    return 0

               remainder //= 10

          return 1

     if remaining_length == 1:
          if remainder % 2 == 0:
               return 0

          lowercase_			:       List[str]									=			0
          for digit in range(10   ):
               lowercase_			:       List[str]									=			digit
               result += reversible_numbers(
                   0  ,    (remainder + 2 * digit) // 10  ,    __SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE   )
          return result

     lowercase_			:       Optional[int]									=			0
     for digita in range(10   ):
          lowercase_			:       Optional[Any]									=			digita

          if (remainder + digita) % 2 == 0:
               lowercase_			:       Optional[Any]									=			ODD_DIGITS
          else:
               lowercase_			:       Dict									=			EVEN_DIGITS

          for digita in other_parity_digits:
               lowercase_			:       Dict									=			digita
               result += reversible_numbers(
                   remaining_length - 2  ,    (remainder + digita + digita) // 10  ,    __SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE  ,    )
     return result



def     lowercase__( __SCREAMING_SNAKE_CASE							:  int = 9   ):
     lowercase_			:       Optional[Any]									=			0
     for length in range(1  ,    max_power + 1   ):
          result += reversible_numbers(__SCREAMING_SNAKE_CASE  ,    0  ,    [0] * length  ,    __SCREAMING_SNAKE_CASE   )
     return result


if __name__ == "__main__":
      print(F"{solution() = }")


"""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     lowercase__( ):
     print('Making key files...'   )
     make_key_files('rsa'  ,    10_24   )
     print('Key files generation successful.'   )



def     lowercase__( __SCREAMING_SNAKE_CASE							:  int   ):
     print('Generating prime p...'   )
     lowercase_			:       List[str]									=			rabinMiller.generate_large_prime(__SCREAMING_SNAKE_CASE   )
     print('Generating prime q...'   )
     lowercase_			:       int									=			rabinMiller.generate_large_prime(__SCREAMING_SNAKE_CASE   )
     lowercase_			:       Union[str, Any]									=			p * q

     print('Generating e that is relatively prime to (p - 1) * (q - 1)...'   )
     while True:
          lowercase_			:       str									=			random.randrange(2 ** (key_size - 1)  ,    2 ** (key_size)   )
          if cryptoMath.gcd(__SCREAMING_SNAKE_CASE  ,    (p - 1) * (q - 1)   ) == 1:
               break

     print('Calculating d that is mod inverse of e...'   )
     lowercase_			:       List[str]									=			cryptoMath.find_mod_inverse(__SCREAMING_SNAKE_CASE  ,    (p - 1) * (q - 1)   )

     lowercase_			:       Any									=			(n, e)
     lowercase_			:       int									=			(n, d)
     return (public_key, private_key)



def     lowercase__( __SCREAMING_SNAKE_CASE							:  str  ,    __SCREAMING_SNAKE_CASE							:  int   ):
     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()

     lowercase_							,						lowercase_			:       int									=			generate_key(__SCREAMING_SNAKE_CASE   )
     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()

