def run(): args = arguments() carrier = args.carrier payload = args.payload try: if payload is None: s = steg_img.IMG(image_path=carrier) s.extract() else: s = steg_img.IMG(payload_path=payload, image_path=carrier) s.hide() except Exception as err: logging.exception("Unexpected error hiding or extracting")
def test_full(self): s = steg_img.IMG(payload_path='./test_data/payload.txt', image_path='./test_data/pug.png') s.hide() assert os.path.exists('./new.png') s_prime = steg_img.IMG(image_path='./new.png') s_prime.extract() assert os.path.exists("./hidden_file.txt") with open("./hidden_file.txt") as extract: with open('./test_data/payload.txt') as orig: e = extract.read().strip() o = orig.read().strip() assert e == o os.remove("./hidden_file.txt") os.remove('./new.png')
def decode(): img = input("Enter image name(with extension) :") def x(): while (True): pixels = [ value for value in imgdata.__next__()[:3] + imgdata.__next__()[:3] + imgdata.__next__()[:3] ] # string of binary data binstr = '' for i in pixels[:8]: if (i % 2 == 0): binstr += '0' else: binstr += '1' data += chr(int(binstr, 2)) if (pixels[-1] % 2 != 0): return data sp = steg_img.IMG(image_path=img) sp.extract() process(Image.open(img)) f = open(file_name, "r") print("Data hidden was") for i in f.readlines(): print(i) proc()
def un_hide(): print( "This module will attempt to retrieve a file hidden within an image.") input_file = input( "Enter the file name or full path of the file to retrieve from: ") if os.path.exists(input_file): output_file = steg_img.IMG(image_path=input_file) print("Preparing to retrieve file from: " + input_file) print( "This may take a long time depending on your system and the file size." ) try: output_file.extract() except: print("Unexpected error ", sys.exc_info()[0], " occured.") print( "Please note this module is still under development and is likely to throw errors." ) print( "If you keep encountering these errors try using a '.bmp' or '.png' image file." ) input("Press 'Enter' to return to main menu.") menu() print("Successfully retrieved file from: " + input_file) input("Press 'Enter' to return to main menu.") menu() else: print( "The file or directory you have chosen does not exist. Please try again." ) input("Press 'Enter' to return to file retrieval menu.") file_hide()
def encode(): img = input("Enter image name(with extension): ") data = input("Enter data to be hidden: ") if (len(data) == 0): raise ValueError('Data is empty') f = open("abc.txt", "w") f.write(data) s = steg_img.IMG(payload_path="abc.txt", image_path=img) s.hide() new_img_name = input("Enter the name of new image(with extension): ") image = Image.open("new.png") image.save(new_img_name) # newimg.save(new_img_name, str(new_img_name.split(".")[1].upper())) proc()
def file_hide(): accepted_ext = (".png", ".PNG", ".BMP", ".bmp") print("This module will attempt to encrypt a given file and then hide it within an image file.") print("Please use a '.png' or '.bmp' file for the target file, the file also needs to be the same size or larger," "than the file you are hiding inside.") print("**Note if you keep getting exceptions try using a '.png' file as this generally has the best success rate.**") input_file = input("Enter the file name or full path of the file to be encrypted and hidden: ") if os.path.exists(input_file): target_file = input("Enter the file name or full path of the target file: ") if target_file.endswith(accepted_ext) !=True: print("Please use a '.png' or '.bmp' file, else this can produce errors.") input("Press 'Enter' to return to the file hider menu.") file_hide() if os.path.exists(target_file): inputsize = os.path.getsize(target_file) inputsizekb = inputsize >> 10 inputsizemb = inputsize >> 20 output_file = steg_img.IMG(payload_path=input_file, image_path=target_file) print("Preparing to hide " + input_file + " into file " + target_file) print("This may take a long time depending on your system and the file size.") try: output_file.hide() outputsize = os.path.getsize(output_file) outputsizekb = outputsize >> 10 outputsizemb = outputsize >> 20 print("File successfully hidden.") print("Size before: " + inputsizemb + "MB or " + inputsizekb + "KB") print("Size after: " + outputsizemb + "MB or " + outputsizekb + "KB") input("Press 'Enter' to return to main menu.") menu() except: print("Unexpected error ",sys.exc_info()[0], " occurred.") print("Please note this module is still under development and is prone to errors.") print("Please try and use a '.png' or '.bmp' file and ensure it is suitably sized to hide the file.") print("**Also note if you keep seeing these errors try using a '.png' file**") input("Press 'Enter' to return to file hider.") file_hide() else: print("The target file does not exist. Please try again.") input("Press 'Enter' to return to file hide menu.") else: print("The file or directory you have chosen does not exist. Please try again.") input("Press 'Enter' to return to file hide menu.") file_hide()
def decodeFile(img_path): decoded = steg_img.IMG(image_path=img_path) decoded.extract()
def encodeFile(msg_path, img_path): encoded = steg_img.IMG(payload_path=msg_path, image_path=img_path) encoded.hide()
help='Path to the carrier file.') parser.add_argument('-p', dest='payload', type=str, default=None, help='Path to the payload file.') args = parser.parse_args() if args.carrier is None: print('[!] No carrier supplied.') parser.print_help() exit(0) return args if __name__ == '__main__': args = arguments() carrier = args.carrier payload = args.payload try: if payload is None: s = steg_img.IMG(image_path=carrier) s.extract() else: s = steg_img.IMG(payload_path=payload, image_path=carrier) s.hide() except Exception as err: print(err)
def decrypt(self, image): self.s_prime = steg_img.IMG(image_path=image) self.s_prime.extract()
def encrypt(self, message, image): self.s = steg_img.IMG(payload_path=message, image_path=image) self.s.hide()