






"""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 			_snake_case    (					)    ->     None:
       print("Making key files..."  )
       make_key_files("rsa"    ,						1_024  )
       print("Key files generation successful."  )

def 			_snake_case    (					lowerCamelCase__     :   int  )    ->     tuple[tuple[int, int], tuple[int, int]]:
       print("Generating prime p..."  )
       lowerCamelCase_	:							Optional[Any]									=rabinMiller.generate_large_prime(snake_case_  )
       print("Generating prime q..."  )
       lowerCamelCase_	:							Dict									=rabinMiller.generate_large_prime(snake_case_  )
       lowerCamelCase_	:							Dict									=p * q

       print("Generating e that is relatively prime to (p - 1) * (q - 1)..."  )
       while True:
              lowerCamelCase_	:							Tuple									=random.randrange(2 ** (key_size - 1)    ,						2 ** (key_size)  )
              if cryptoMath.gcd(snake_case_    ,						(p - 1) * (q - 1)  ) == 1:
                     break

       print("Calculating d that is mod inverse of e..."  )
       lowerCamelCase_	:							List[Any]									=cryptoMath.find_mod_inverse(snake_case_    ,						(p - 1) * (q - 1)  )

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

def 			_snake_case    (					lowerCamelCase__     :   str    ,						lowerCamelCase__     :   int  )    ->     None:




       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()

       lowerCamelCase_							,						lowerCamelCase_	:							List[str]									=generate_key(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()











"""simple docstring"""



# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from argparse import ArgumentParser

from accelerate.commands.config import get_config_parser
from accelerate.commands.env import env_command_parser
from accelerate.commands.launch import launch_command_parser
from accelerate.commands.test import test_command_parser
from accelerate.commands.tpu import tpu_command_parser

def 			_snake_case    (					)    ->     Tuple:
							lowerCamelCase_	:							Optional[int]									=ArgumentParser("Accelerate CLI tool"    ,						usage="accelerate <command> [<args>]"    ,						allow_abbrev=lowerCamelCase__  )
							lowerCamelCase_	:							Optional[int]									=parser.add_subparsers(help="accelerate command helpers"  )

							# Register commands
							get_config_parser(subparsers=lowerCamelCase__  )
							env_command_parser(subparsers=lowerCamelCase__  )
							launch_command_parser(subparsers=lowerCamelCase__  )
							tpu_command_parser(subparsers=lowerCamelCase__  )
							test_command_parser(subparsers=lowerCamelCase__  )

							# Let's go
							lowerCamelCase_	:							int									=parser.parse_args()

							if not hasattr(lowerCamelCase__    ,						"func"  ):
														parser.print_help()
														exit(1  )

							# Run
							args.func(lowerCamelCase__  )


if __name__ == "__main__":
						main()



