1
0
Fork 0
mirror of https://github.com/GeoffreyFrogeye/steginack.git synced 2024-12-21 22:30:36 +01:00

Fixed image hiding and added inverse

This commit is contained in:
Geoffrey Frogeye 2015-04-23 10:39:08 +02:00
parent 63a4af6e0f
commit 3f34e955c8

View file

@ -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)