Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@anthonykasza
Created December 13, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonykasza/b90e2ca6e40c8294dbfc to your computer and use it in GitHub Desktop.
Save anthonykasza/b90e2ca6e40c8294dbfc to your computer and use it in GitHub Desktop.
punch holes in a file
from StringIO import StringIO
import sys
import random
if len(sys.argv) != 3:
print "usage: hole_punch.py in_filename out_filenae"
exit()
ifname = sys.argv[1]
ofname = sys.argv[2]
with open(ifname, 'rb') as f:
d = StringIO(f.read())
l = d.len
percent = 0.1
holes = random.randint(0, int(d.len * percent))
for i in range(0, holes):
d.seek( random.randint(0, d.len) )
d.write('\x00')
d.seek(0)
with open(ofname, 'wb') as f:
f.write(d.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment