Adde CLI support for the fast Ackermann generator

This commit is contained in:
AdrienCos 2019-06-04 11:36:40 -04:00
parent 45cdb9a3a5
commit 8f8cd483fd
No known key found for this signature in database
GPG key ID: 97AD9AEBCA16D08D

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
#-*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Stéganô - Stéganô is a basic Python Steganography module. # Stéganô - Stéganô is a basic Python Steganography module.
# Copyright (C) 2010-2017 Cédric Bonhomme - https://www.cedricbonhomme.org # Copyright (C) 2010-2017 Cédric Bonhomme - https://www.cedricbonhomme.org
@ -40,6 +40,19 @@ import argparse
parser = argparse.ArgumentParser(prog='stegano-lsb-set') parser = argparse.ArgumentParser(prog='stegano-lsb-set')
subparsers = parser.add_subparsers(help='sub-command help', dest='command') subparsers = parser.add_subparsers(help='sub-command help', dest='command')
class ValidateGenerator(argparse.Action):
def __call__(self, parser, args, values, option_string=None):
valid_generators = [generator[0] for generator in inspect.getmembers(
generators, inspect.isfunction)]
# Verify that the generator is valid
generator = values[0]
if generator not in valid_generators:
raise ValueError("Unknown generator: %s" % generator)
# Set the generator_function arg of the parser
setattr(args, self.dest, values)
# Subparser: Hide # Subparser: Hide
parser_hide = subparsers.add_parser('hide', help='hide help') parser_hide = subparsers.add_parser('hide', help='hide help')
# Original image # Original image
@ -52,9 +65,8 @@ parser_hide.add_argument("-e", "--encoding", dest="encoding",
# Generator # Generator
parser_hide.add_argument("-g", "--generator", dest="generator_function", parser_hide.add_argument("-g", "--generator", dest="generator_function",
# choices=[generator[0] for generator in \ action=ValidateGenerator,
# inspect.getmembers(generators, inspect.isfunction)], nargs='*', required=True, help="Generator (with optional arguments)")
nargs='*', required=True, help="Generator")
parser_hide.add_argument("-s", "--shift", dest="shift", parser_hide.add_argument("-s", "--shift", dest="shift",
default=0, help="Shift for the generator") default=0, help="Shift for the generator")
@ -80,9 +92,8 @@ parser_reveal.add_argument("-e", "--encoding", dest="encoding",
help="Specify the encoding of the message to reveal." + help="Specify the encoding of the message to reveal." +
" UTF-8 (default) or UTF-32LE.") " UTF-8 (default) or UTF-32LE.")
parser_reveal.add_argument("-g", "--generator", dest="generator_function", parser_reveal.add_argument("-g", "--generator", dest="generator_function",
# choices=[generator[0] for generator in \ action=ValidateGenerator,
# inspect.getmembers(generators, inspect.isfunction)], nargs='*', required=True, help="Generator (with optional arguments)")
nargs='*', required=True, help="Generator")
parser_reveal.add_argument("-s", "--shift", dest="shift", parser_reveal.add_argument("-s", "--shift", dest="shift",
default=0, help="Shift for the generator") default=0, help="Shift for the generator")
parser_reveal.add_argument("-o", dest="secret_binary", parser_reveal.add_argument("-o", dest="secret_binary",
@ -105,8 +116,8 @@ if arguments.command != 'list-generators':
try: try:
if (len(arguments.generator_function) > 1): if (len(arguments.generator_function) > 1):
generator = getattr(generators, arguments.generator_function[0])\ generator = getattr(generators, arguments.generator_function[0])(
(*[int(e) for e in arguments.generator_function[1:]]) *[int(e) for e in arguments.generator_function[1:]])
else: else:
generator = getattr(generators, arguments.generator_function[0])() generator = getattr(generators, arguments.generator_function[0])()