moth/puzzles/steg/200/encode

34 lines
657 B
Plaintext
Raw Normal View History

2010-10-12 16:58:34 -06:00
#! /usr/bin/python
import sys
import os
import gzip
import md5
partlen = 8
key = sys.stdin.read().strip()
hexofkey = key.encode('hex')
garbage = os.fdopen(3).read()
keyparts = []
for i in range(0, len(hexofkey), partlen):
part = hexofkey[i:i+partlen]
keyparts.append(part)
textpartlen = len(garbage) / len(keyparts)
for i in range(len(keyparts)):
offset = i*textpartlen
if i == len(keyparts) - 1:
textpart = garbage[offset:]
else:
textpart = garbage[offset:offset+textpartlen]
fn = keyparts[i] + '.txt'
gf = gzip.GzipFile(filename=fn, mode='ab', fileobj=sys.stdout)
gf.write(textpart)
gf.close()