moth/packages/steg/100/encode

35 lines
668 B
Plaintext
Raw Normal View History

2010-10-06 17:20:00 -06:00
#! /usr/bin/python
import os
import sys
import md5
import cStringIO as StringIO
2010-10-06 17:20:00 -06:00
plaintext = sys.stdin
inf = os.fdopen(3)
2010-10-06 17:20:00 -06:00
outf = sys.stdout
for i in range(3):
outf.write(inf.readline())
2010-10-06 17:20:00 -06:00
# Set the low-order bits in output file
i = 0
while True:
c = plaintext.read(1)
if c:
c = ord(c)
2010-10-06 17:20:00 -06:00
else:
c = 0
img_bytes = inf.read(8)
if not img_bytes:
break
if len(img_bytes) < 8:
outf.write(img_bytes)
break
for j in range(8):
bit = 7 - j
img_byte = ord(img_bytes[j]) & 0xFE
noise_bit = (c & (1<<bit)) >> bit
out_byte = img_byte | noise_bit
outf.write(chr(out_byte))