Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Created June 21, 2012 14:31
Show Gist options
  • Select an option

  • Save bmispelon/2966050 to your computer and use it in GitHub Desktop.

Select an option

Save bmispelon/2966050 to your computer and use it in GitHub Desktop.
Deobfuscating exercise
# http://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python
from struct import pack
WIDTH, HEIGHT = 1500, 1000
f = open('M.bmp','wb')
f.write('BM' + pack('<QIIHHHH', WIDTH * HEIGHT * 3 + 26, 26, 12, WIDTH, HEIGHT, 1, 24))
def pixel(T):
r = (T * 80) + (T ** 9 * 255) - (950 * T ** 99)
g = (T * 70) - (880 * T ** 18) + (701 * T ** 9)
b = T * 255 ** (1 - T ** 45 * 2)
return r, g, b
def foo(V, B, c):
if not c:
return c
if (abs(V) < 6):
return foo(V * V + B, B, c - 1)
else:
return (2 + c - 4 * abs(V) ** -0.4) / 255
for X in xrange(WIDTH * HEIGHT):
row, col = divmod(X, WIDTH)
c = 0
for i in xrange(9):
row2, col2 = divmod(i, 3)
c += foo(
0,
complex(
col2 / 3. + col,
-(row + row2 / 3. - HEIGHT / 2)
) * 2.5 / HEIGHT - 2.7,
255
) ** 2
f.write(pack('BBB', *pixel(c / 9)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment