import sys
import Image, ImageColor

key = 2**6 * 5 * 19 * 12043 * 216493 * 836256503069278983442067

#import binascii
#buf = binascii.a2b_hex (('%x' % key).rjust (32, '0'))

def binary (x):
	if x == 0:
		return []
	else:
		return [x & 1] + binary (x >> 1)

buf = binary (key)
#print >> sys.stderr, buf

import math
width = int (math.floor (math.sqrt (len (buf))))
height = width
if len (buf) % width:
	height += 1
#print >> sys.stderr, width, height

i = Image.new ('RGB', (width, height), ImageColor.getrgb ('gray'))

colors = {0: ImageColor.getrgb ('black'),
	      1: ImageColor.getrgb ('white')}

y = x = 0
for bit in buf:
	i.putpixel ((x, y), colors[bit])
	x += 1
	if x == width:
		x = 0
		y += 1
	if y == height:
		break

import PngImagePlugin
pi = PngImagePlugin.PngInfo ()
pi.add_text ('Title', 'Illegal Image')
pi.add_text ('Description', 'Pixels represent bits in ascending order of significance. Black is a 0, White is a 1. Grey is used to pad the image out to a rectangular size.', zip = True)
pi.add_text ('Source', 'AACS processing key published by Proskauer Rose LLP, <http://www.chillingeffects.org/notice.cgi?sID=3218>', zip = True)

i.save (sys.stdout, 'PNG', pnginfo = pi)
