Integrate pad rewriting into cli.
[easyotp.git] / mix.py
blobc5105de037d177e2a0bdadf99c2a4a9ca2f5dab1
1 #!/bin/env python
2 # Created:20080610
3 # By Jeff Connelly
5 # Mix random data, compressing low-entropy into high-entropy
7 import hashlib
8 import sys
9 import math
11 hash = hashlib.sha512
13 # in / out
14 ratio = 2
16 if len(sys.argv) > 1:
17 ratio = float(sys.argv[1])
19 hash_size = len(hash("").digest())
20 bytes_to_read = int(math.floor(hash_size * ratio))
22 while True:
23 input = sys.stdin.read(bytes_to_read)
24 if len(input) == 0:
25 break
26 output = hash(input).digest()
27 sys.stdout.write(output)
28 if len(input) < bytes_to_read:
29 break