def test_steganogrified_name(): """Data will be hidden in a file with steganogrified at the end, when no output file name is provided.""" clean_message_image = copy2( CLEAN_PNG_LOCATION, CLEAN_PNG_LOCATION[:-4] + "_test_message_steganogrified_name.png") clean_file_image = copy2( CLEAN_PNG_LOCATION, CLEAN_PNG_LOCATION[:-4] + "_test_file_steganogrified_name.png") hidden_message = "Hidden text from test_steganogrified_name." file_to_hide = "tests/FileToHide.zip" stegs = Steganographer() hidden_message_fname = stegs.steganographer_hide(clean_message_image, hidden_message) steganogrified_message_fname = clean_message_image[:-4] + "Steganogrified.png" hidden_file_fname = stegs.steganographer_hide_file(clean_file_image, file_to_hide) steganogrified_file_fname = clean_file_image[:-4] + "Steganogrified.png" assert hidden_message_fname == steganogrified_message_fname assert os.path.isfile(steganogrified_message_fname) assert hidden_file_fname == steganogrified_file_fname assert os.path.isfile(steganogrified_file_fname) os.remove(clean_message_image) os.remove(hidden_message_fname) os.remove(clean_file_image) os.remove(hidden_file_fname)
def test_steganographer_hide_file(): """A file can be hidden inside of an image and the image created is not corrupt""" clean_image = CLEAN_PNG_LOCATION dirty_image = "tests/dirtyImage_test_steganographer_hide_file.png" file_to_hide = "tests/FileToHide.zip" stegs = Steganographer() hidden_fname = stegs.steganographer_hide_file(clean_image, file_to_hide, dirty_image) with open(clean_image, 'rb') as clean, open(hidden_fname, 'rb') as dirty: assert clean.read() != dirty.read() assert compare_images(clean_image, hidden_fname) < 19000 try: Image.open(hidden_fname) except OSError: pytest.fail("Image is corrupt " + hidden_fname) os.remove(hidden_fname)
def main(): """Given an image and a message or file steganographer will hide the message or file in the bits of the image.""" parser = argparse.ArgumentParser( description= "hides a message in a file or returns a message hidden in a file") parser.add_argument( "input", help="file to hide a message in or file to reveal a message from") parser.add_argument("-m", "--message", help="message to be hidden in the input file") parser.add_argument( "-o", "--output", help= "name of output file to hide message in or to write revealed message", default='') parser.add_argument("-f", "--file", help="file to be hidden in the input file") parser.add_argument("-r", "--reveal", action='store_true', help="a file will be revealed") parser.add_argument("-v", "--version", action='version', version="steganographer {}".format( pkg_resources.get_distribution('pip').version), help="show version and exit") args = parser.parse_args() stegs = Steganographer() # There is a message to hide. if args.message: hidden_fname = stegs.steganographer_hide(args.input, args.message, args.output) print("The message has been hidden in " + hidden_fname) # There is a file to hide. elif args.file: hidden_fname = stegs.steganographer_hide_file(args.input, args.file, args.output) print("The file " + args.file + " has been hidden in " + hidden_fname) # Revealing a file. elif args.reveal: revealed_data, file_name = stegs.steganographer_reveal(args.input) if args.output: file_name = args.output with open(file_name, 'wb') as rev_file: rev_file.write(revealed_data) print("The hidden file was revealed in " + file_name) # Revealing a message. else: hidden_message = stegs.steganographer_reveal( args.input)[0].decode('utf-8') if args.output: open(args.output, 'w', encoding='utf-8').write(hidden_message) print("The hidden message was written to " + args.output) else: try: print("The hidden message was...\n" + hidden_message) except UnicodeEncodeError: # pragma: no cover output_name = args.input.split('.')[0] + '_message.txt' print( "The hidden message contains unsupported unicode characters and cannot be fully displayed " + "here. The correct message has been written to", output_name) print(hidden_message.encode('utf-8')) open(output_name, 'w', encoding='utf-8').write(hidden_message)