From 3f34e955c84835d603c33ab15f4d4c5f14ab110a Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Thu, 23 Apr 2015 10:39:08 +0200 Subject: [PATCH] Fixed image hiding and added inverse --- steginack.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/steginack.py b/steginack.py index 802b7e7..483c7bb 100755 --- a/steginack.py +++ b/steginack.py @@ -18,14 +18,14 @@ def hideInFile(infile, hidefile, bits, outfile): for x in range(inim.size[0]): for y in range(inim.size[1]): incol = inim.getpixel((x, y)) - hidecol = inim.getpixel((x, y)) + hidecol = hideim.getpixel((x, y)) outcol = [] for cp in range(len(incol)): inbyt = get_bin(incol[cp], 8) hidebyt = get_bin(hidecol[cp], 8) outbyt = list(inbyt) for bit in range(bits): - outbyt[-bit - 1] = inbyt[1] + outbyt[-bit - 1] = hidebyt[bit] outcol.append(int(''.join(outbyt), 2)) outim.putpixel((x, y), tuple(outcol)) eta.print_status(x * inim.size[1] + y) @@ -35,10 +35,23 @@ def hideInFile(infile, hidefile, bits, outfile): outim.save(outfile, 'PNG') -def inverseFile(infile, bits, outfile): +def inverseFile(infile, outfile): inim = Image.open(infile) outim = Image.new('RGB', inim.size) - assert 0 <= bits <= 8 + eta = ETA(inim.size[0] * inim.size[1]) + for x in range(inim.size[0]): + for y in range(inim.size[1]): + incol = inim.getpixel((x, y)) + outcol = [] + for cp in range(len(incol)): + inbyt = get_bin(incol[cp], 8) + outbyt = list(inbyt) + for bit in range(8): + outbyt[-bit - 1] = inbyt[bit] + outcol.append(int(''.join(outbyt), 2)) + outim.putpixel((x, y), tuple(outcol)) + eta.print_status(x * inim.size[1] + y) + eta.done() inim.close() outim.save(outfile, 'PNG') @@ -46,11 +59,11 @@ def inverseFile(infile, bits, outfile): if __name__ == '__main__': parser = argparse.ArgumentParser(description="Hide an image inside another and decode images") parser.add_argument('infile', metavar='INFILE', type=str, help="Input file") - parser.add_argument('bits', metavar='BITS', type=int, help="Number of bits to use") parser.add_argument('outfile', metavar='OUTFILE', type=str, help="Output file") + parser.add_argument('-b', '--bits', type=int, help="Number of bits to use for hiding") parser.add_argument('-s', '--hide', type=str, help="File to hide") args = parser.parse_args() if args.hide: hideInFile(args.infile, args.hide, args.bits, args.outfile) else: - inverseFile(args.infile, args.bits, args.outfile) + inverseFile(args.infile, args.outfile)