

"""simple docstring"""





import operator




def   _A  (  UpperCamelCase_					:	list,      UpperCamelCase_					:	bool = False,      UpperCamelCase_					:	list | None = None)     ->						list:
   '''simple docstring'''


   __lowercase								=						operator.lt if reverse else operator.gt
   __lowercase								=						solution or []

   if not arr:
      return solution

   __lowercase								=						[arr.pop(0)]
   for i, item in enumerate(UpperCamelCase_):
      if _operator(UpperCamelCase_,      sublist[-1]):
         sublist.append(UpperCamelCase_)
         arr.pop(UpperCamelCase_)

    #  merging sublist into solution list
   if not solution:
      solution.extend(UpperCamelCase_)
   else:
      while sublist:
         __lowercase								=						sublist.pop(0)
         for i, xx in enumerate(UpperCamelCase_):
            if not _operator(UpperCamelCase_,      UpperCamelCase_):
               solution.insert(UpperCamelCase_,      UpperCamelCase_)
               break
         else:
            solution.append(UpperCamelCase_)

   strand_sort(UpperCamelCase_,      UpperCamelCase_,      UpperCamelCase_)
   return solution


if __name__ == "__main__":
   assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
   assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]







"""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",      1024)
   print("Key files generation successful.")




def   _A  (  UpperCamelCase_					:	int)     ->						tuple[tuple[int, int], tuple[int, int]]:
   '''simple docstring'''


   print("Generating prime p...")
   __lowercase								=						rabinMiller.generate_large_prime(UpperCamelCase_)
   print("Generating prime q...")
   __lowercase								=						rabinMiller.generate_large_prime(UpperCamelCase_)
   __lowercase								=						p * q

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

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




def   _A  (  UpperCamelCase_					:	str,      UpperCamelCase_					:	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()

   __lowercase		,__lowercase								=						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()




