| 93 | |
| 94 | |
| 95 | def run_cipher(cipher, decipher): |
| 96 | from os import urandom |
| 97 | import random |
| 98 | import time |
| 99 | |
| 100 | BLOCK_SIZE = 16384 |
| 101 | rounds = 1 * 1024 |
| 102 | plain = urandom(BLOCK_SIZE * rounds) |
| 103 | |
| 104 | results = [] |
| 105 | pos = 0 |
| 106 | print('test start') |
| 107 | start = time.time() |
| 108 | while pos < len(plain): |
| 109 | l = random.randint(100, 32768) |
| 110 | c = cipher.update(plain[pos:pos + l]) |
| 111 | results.append(c) |
| 112 | pos += l |
| 113 | pos = 0 |
| 114 | c = b''.join(results) |
| 115 | results = [] |
| 116 | while pos < len(plain): |
| 117 | l = random.randint(100, 32768) |
| 118 | results.append(decipher.update(c[pos:pos + l])) |
| 119 | pos += l |
| 120 | end = time.time() |
| 121 | print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start))) |
| 122 | assert b''.join(results) == plain |
| 123 | |
| 124 | |
| 125 | def test_find_library(): |