import random fin = open("output.bmp","r"); fin.read(6) seed = (ord(fin.read(1)) << 8) + ord(fin.read(1)) length = (ord(fin.read(1)) << 8) + ord(fin.read(1)) print hex(seed) + "-" + hex(length) fin.read(54-10) image = fin.read() print "image " + str(len(image)) random.seed(seed) byte = 0 current_byte_size = 0 for ind in xrange(length*8): randnum = random.randint(0,len(image)-1) #print randnum byte = byte + (ord(image[randnum]) % 2) current_byte_size += 1 if current_byte_size > 7: print chr(byte), byte = 0 current_byte_size = 0 else: byte = byte << 1