forked from qwj/python-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher_speed.py
More file actions
30 lines (26 loc) · 734 Bytes
/
cipher_speed.py
File metadata and controls
30 lines (26 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os, time, sys, os
from pproxy.cipher import MAP
from pproxy.cipherpy import MAP as MAP_PY
def test_cipher(A, size=32*1024, repeat=128):
for i in range(repeat):
key = os.urandom(A.KEY_LENGTH)
iv = os.urandom(A.IV_LENGTH)
a = A(key)
a.setup_iv(iv)
s = os.urandom(size)
s2 = a.encrypt(s)
a = A(key, True)
a.setup_iv(iv)
s4 = a.decrypt(s2)
assert s == s4
cipher = sys.argv[1] if len(sys.argv) > 1 else None
if cipher and cipher.endswith('-py'):
A = MAP_PY.get(cipher[:-3])
else:
A = MAP.get(cipher)
if A:
t = time.perf_counter()
test_cipher(A)
print(cipher, time.perf_counter()-t)
else:
print('unknown cipher', cipher)