1
0
Fork 0
mirror of https://github.com/dirtbags/moth.git synced 2025-01-06 03:50:56 -07:00
moth/packages/steg/100/encode
2010-10-25 11:15:12 -06:00

34 lines
668 B
Python
Executable file

#! /usr/bin/python
import os
import sys
import md5
import cStringIO as StringIO
plaintext = sys.stdin
inf = os.fdopen(3)
outf = sys.stdout
for i in range(3):
outf.write(inf.readline())
# Set the low-order bits in output file
i = 0
while True:
c = plaintext.read(1)
if c:
c = ord(c)
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))