snappy-fox/example/alterrandom.py

19 lines
316 B
Python
Raw Normal View History

2024-02-19 11:58:58 +01:00
import sys
import random
prob = int(sys.argv[3])
substbyte = int(sys.argv[4])
with open(sys.argv[1], "rb") as f:
indata = bytearray(f.read())
for b in range(len(indata)):
x = random.randint(0, 10000)
if x < prob:
# Alter the data
indata[b] = substbyte
with open(sys.argv[2], "wb") as f:
f.write(indata)