diff options
author | Lars Wirzenius <liw@iki.fi> | 2007-07-24 22:23:45 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@iki.fi> | 2007-07-24 22:23:45 +0300 |
commit | d98cfeb4f6892180b3522df33cfae6366864efb2 (patch) | |
tree | db2da5153c6a9a351469c92c0f972157bccb6480 | |
parent | c1891c8c9eadf22e99761297f60ab7f14995e921 (diff) | |
download | genbackupdata-d98cfeb4f6892180b3522df33cfae6366864efb2.tar.gz |
Replaced algorithm for generating binary junk with a new one.
-rw-r--r-- | genbackupdata.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/genbackupdata.py b/genbackupdata.py index 7ca7c60..ecc82de 100644 --- a/genbackupdata.py +++ b/genbackupdata.py @@ -256,15 +256,31 @@ class BackupData: def generate_binary_data(self, size): """Generate SIZE bytes of more or less random binary junk""" - self.init_prng() - hasher = md5.new() - result = [] - while size > 0: - hasher.update(chr(self._prng.getrandbits(8))) - chunk = hasher.digest()[:size] - size -= len(chunk) - result.append(chunk) - return "".join(result) + + # The following code has had some fine manual fine tuning done + # to it. This has made it ugly, but faster. On a 1.2 MHz Intel + # Pentium M, it generates around 6 MB/s. + + chunks = [] + sum = md5.new() + chunk_size = md5.digest_size + + initial_bytes = min(size, chunk_size * 8) + for i in range(initial_bytes / chunk_size): + sum.update(chr(random.getrandbits(8))) + chunks.append(sum.digest()) + + size -= len(chunks) * chunk_size + for i in range(size / chunk_size): + sum.update("a") + chunks.append(sum.digest()) + + if size % chunk_size > 0: + sum.update(chr(random.getrandbits(8))) + chunks.append(sum.digest()[:size % chunk_size]) + + return "".join(chunks) + def create_subdirectories(self, filename): """Create the sub-directories that are needed to create filename""" |