diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-12-02 15:13:20 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-12-02 15:13:20 +0000 |
commit | 5a9bc498377f1d68b31ee4d301d47d91fe7d3907 (patch) | |
tree | e3617d32fee5242afe2cf77a369e7f691689b5ed | |
parent | 7823c6d8ae048fea7566543c38d02dd87c3ee3e0 (diff) | |
download | genbackupdata-5a9bc498377f1d68b31ee4d301d47d91fe7d3907.tar.gz |
Add a new junk generator.
It turns out to be about 150% faster than the previous
relevant candiate (sha1ofgetrandbits2). Also, almost 100%
faster than the previous faster candidate, but since that
produces repetition, it is no longer relevant.
-rw-r--r-- | binaryjunk.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/binaryjunk.py b/binaryjunk.py index 5dde88e..4df82ca 100644 --- a/binaryjunk.py +++ b/binaryjunk.py @@ -83,6 +83,22 @@ def sha1ofgetrandbits2(size): return "".join(chunks) +def sha512ofgetrandbits(size): + """catenate successive SHA512 of random byte stream""" + chunks = [] + sum = hashlib.sha512() + chunk_size = len(sum.digest()) + for byte in [chr(random.getrandbits(8)) for i in xrange(size / chunk_size)]: + sum.update(byte) + chunk = sum.digest() + chunks.append(chunk) + if size % chunk_size > 0: + sum.update(chr(random.getrandbits(8))) + chunk = sum.digest() + chunks.append(chunk[:size % chunk_size]) + return "".join(chunks) + + def md5ofrandomandstatic(size): """MD5 first of random byte stream, then constant""" chunks = [] @@ -166,6 +182,7 @@ funcs = [ md5ofrandomandstatic, md5ofrandomandstatic2, sha1ofrandomandstatic2, + sha512ofgetrandbits, ] |