Skip to content

Instantly share code, notes, and snippets.

@justinfay
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save justinfay/aff34da39331bfe79934 to your computer and use it in GitHub Desktop.

Select an option

Save justinfay/aff34da39331bfe79934 to your computer and use it in GitHub Desktop.
from random import SystemRandom
random = SystemRandom()
INPUT_FILE = '6944719-tree-sunset-reflection.bmp'
OUTPUT_FILE = 'glitch.bmp'
with open(INPUT_FILE, 'rb') as rh:
with open(OUTPUT_FILE, 'wb') as wh:
count = 0
while True:
next = rh.read(1)
if next == '':
break
if count % 176 == 0:
next = next.replace(b'\x07', b'\x32')
next = next.replace(b'\x0B', b'\x0A\x0D')
if count % 122 == 0:
next = next.replace(b'\x24', b'\x26')
next = next.replace(b'\x0D', b'\x0A\x0D')
if count % 76 == 0:
next = next.replace(b'\x0A', b'\x0A\x0D')
if count % 150 == 0:
try:
if 46 < ord(next) < 57:
next = str(ord(next) + 1)
except:
next = next
if count % 17 and count > 4000:
next = rh.read(1) + rh.read(1) + next
if count > 3000 and count % 30 == 0:
next = [next]
for i in xrange(10):
next.append(rh.read(30))
random.shuffle(next)
next = ''.join(next)
wh.write(next)
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment