Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mmap, sys, random
- target = open(sys.argv[1],'rb+')
- buffer = mmap.mmap(target.fileno(), 0)
- # flip 1% of the bits
- flip_ratio = .01
- target.seek(2, 0)
- file_size = target.tell()
- target.seek(0, 0)
- for _ in xrange(int(file_size * flip_ratio)):
- idx = random.randint(0, (file_size * 8) - 1)
- buffer[idx / 8] ^= 1 << (idx % 8)
- buffer.close()
- target.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement