Advertisement
tari

Untitled

Jul 15th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. import mmap, sys, random
  2.  
  3. target = open(sys.argv[1],'rb+')
  4. buffer = mmap.mmap(target.fileno(), 0)
  5.  
  6. # flip 1% of the bits
  7. flip_ratio = .01
  8.  
  9. target.seek(2, 0)
  10. file_size = target.tell()
  11. target.seek(0, 0)
  12.  
  13. for _ in xrange(int(file_size * flip_ratio)):
  14.     idx = random.randint(0, (file_size * 8) - 1)
  15.     buffer[idx / 8] ^= 1 << (idx % 8)
  16.  
  17. buffer.close()
  18. target.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement