From fc93cc6e371e040ec3c87eff0f997afd3267bcb8 Mon Sep 17 00:00:00 2001 From: Jeff Connelly Date: Tue, 10 Jun 2008 20:55:45 -0700 Subject: [PATCH] Add mixing program. --- mix.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 mix.py diff --git a/mix.py b/mix.py new file mode 100644 index 0000000..c5105de --- /dev/null +++ b/mix.py @@ -0,0 +1,30 @@ +#!/bin/env python +# Created:20080610 +# By Jeff Connelly +# +# Mix random data, compressing low-entropy into high-entropy + +import hashlib +import sys +import math + +hash = hashlib.sha512 + +# in / out +ratio = 2 + +if len(sys.argv) > 1: + ratio = float(sys.argv[1]) + +hash_size = len(hash("").digest()) +bytes_to_read = int(math.floor(hash_size * ratio)) + +while True: + input = sys.stdin.read(bytes_to_read) + if len(input) == 0: + break + output = hash(input).digest() + sys.stdout.write(output) + if len(input) < bytes_to_read: + break + -- 2.11.4.GIT