Skip to content

Instantly share code, notes, and snippets.

@bewt85
Created June 8, 2014 16:41
Show Gist options
  • Save bewt85/05737df5f3360c510a42 to your computer and use it in GitHub Desktop.
Save bewt85/05737df5f3360c510a42 to your computer and use it in GitHub Desktop.
Creates a file which appears random but is actually deterministic
#!/usr/bin/env python
from hashlib import md5
import argparse, os
parser = argparse.ArgumentParser(description="Makes pseudo-random but deterministic files of ascii text")
parser.add_argument('output_file', help="Location of output file")
parser.add_argument('size', nargs='?', default=1024, type=int, help="Size in bytes of output file")
parser.add_argument('seed', nargs='?', default=None, help="A seed value to differentiate output files")
args = parser.parse_args()
args.seed = os.path.basename(args.output_file) if args.seed == None else args.seed
with open(args.output_file, 'w') as output_file:
m = md5()
for i in range(0, args.size-32, 32):
m.update(args.seed)
output_file.write(m.hexdigest())
m.update(args.seed)
output_file.write(m.hexdigest()[:args.size-(i+32)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment