






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


def 				snake_case__							(							UpperCAmelCase							:  Union[str, Any]       ):
    print("Generating prime p..."       )
    lowerCAmelCase__   :Union[str, Any]      							=				rabinMiller.generate_large_prime(lowerCAmelCase__       )
    print("Generating prime q..."       )
    lowerCAmelCase__   :List[str]      							=				rabinMiller.generate_large_prime(lowerCAmelCase__       )
    lowerCAmelCase__   :Optional[int]      							=				p * q

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

    print("Calculating d that is mod inverse of e..."       )
    lowerCAmelCase__   :Dict      							=				cryptoMath.find_mod_inverse(lowerCAmelCase__    ,			(p - 1) * (q - 1)       )

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


def 				snake_case__							(							UpperCAmelCase							:  Any    ,			UpperCAmelCase							:  List[str]       ):
    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__   :Tuple      							=				generate_key(lowerCAmelCase__       )
    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()











from argparse import ArgumentParser

from datasets.commands.convert import ConvertCommand
from datasets.commands.dummy_data import DummyDataCommand
from datasets.commands.env import EnvironmentCommand
from datasets.commands.run_beam import RunBeamCommand
from datasets.commands.test import TestCommand
from datasets.utils.logging import set_verbosity_info


def 				snake_case__							(							UpperCAmelCase							:  Dict       ):
    return {key.lstrip("-"       ): value for key, value in zip(unknown_args[::2]    ,			unknown_args[1::2]       )}


def 				snake_case__							(							):
    lowerCAmelCase__   :str      							=				ArgumentParser(
        "HuggingFace Datasets CLI tool"    ,			usage="datasets-cli <command> [<args>]"    ,			allow_abbrev=UpperCAmelCase       )
    lowerCAmelCase__   :Any      							=				parser.add_subparsers(help="datasets-cli command helpers"       )
    set_verbosity_info()

    # Register commands
    ConvertCommand.register_subcommand(UpperCAmelCase       )
    EnvironmentCommand.register_subcommand(UpperCAmelCase       )
    TestCommand.register_subcommand(UpperCAmelCase       )
    RunBeamCommand.register_subcommand(UpperCAmelCase       )
    DummyDataCommand.register_subcommand(UpperCAmelCase       )

    # Parse args
    lowerCAmelCase__							,lowerCAmelCase__   :int      							=				parser.parse_known_args()
    if not hasattr(UpperCAmelCase    ,			"func"       ):
        parser.print_help()
        exit(1       )
    lowerCAmelCase__   :Optional[int]      							=				parse_unknown_args(UpperCAmelCase       )

    # Run
    lowerCAmelCase__   :str      							=				args.func(UpperCAmelCase    ,			**UpperCAmelCase       )
    service.run()


if __name__ == "__main__":
 main()



