All pastes #1085830 Raw Edit

Unnamed

public python v1 · immutable
#1085830 ·published 2008-07-29 01:48 UTC
rendered paste body
import sys, random, binascii, zlib, structfrom PIL import Imageclass Imagestream(object) :    def __init__(self, data) :        self.data = data        self.reset_structs()            def reset_structs(self) :        self.hash = 0x811c9dc5        self.next_pos = 0x0000b400        self.maxsize = 0x00010000        self.unknown = 0x00000001        self.mask = 0xfffffff8        self.invmask = 0x00000007        self.start_pos = 0x0000b400        def get_byte(self) :        ok = True        byte = 0                for i in xrange(8) :            if (self.next_pos >= self.maxsize) :                print "exceeding maxsize", self.next_pos                sys.exit()            scramble_byte = (self.next_pos & self.invmask) | (self.data[self.next_pos] & self.mask) & 0xff                        self.hash = (self.hash * 0x1000193) & 0xffffffff            self.hash ^= scramble_byte            #print hex(self.hash)                        if self.data[self.next_pos] & self.unknown :                eax = 0x80            else :                eax = 0                            if (self.hash & 0x8000) :                eax = 0x80 - eax                            byte = (byte >> 1) | eax                        if (self.next_pos & 1) :                self.next_pos >>= 1                self.next_pos ^= self.start_pos            else :                self.next_pos >>= 1                                            ok = 1            if (self.next_pos == self.start_pos) :                ok = 0                break                            if ok == 0 :                print "Break!"                sys.exit()                return (ok, byte)    im = Image.open(sys.argv[1])ims = list(im.tostring())list = []for y in xrange(128) :    for x in xrange(128) :        (r,g,b,a) = im.getpixel((x,y))                list.extend((b,g,r,a))        stream = Imagestream(list)data = ""while True :    (al, byte) = stream.get_byte()    if al == 0 :        break    else :        data += chr(byte)print "Header data:", binascii.b2a_hex(data[0:8])length = struct.unpack("<L", data[4:8])[0]of = open(sys.argv[1] + ".txt", "wb")of.write(zlib.decompress(data[8:8+length]))of.close()print "Checksum data:", binascii.b2a_hex(data[8+length:8+length+12])