Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import timeit
- encrypt_check = "print(all(c[i] == t.encrypt_block(m[i]) for i in range(N)))"
- decrypt_check = "print(all(m[i] == t.decrypt_block(c[i]) for i in range(N)))"
- test_setup = """
- from skein import threefish
- import hashlib
- import string
- import random
- key = hashlib.sha512(b'password').digest() # 64 byte key (512 bits)
- tweak = b'This is my tweak'
- t = threefish(key, tweak)
- m = []
- c = []
- N = 50000
- for i in range(N):
- m.append(bytes("".join(random.choice(string.printable) for i in range(64)), encoding='utf8'))
- print("Done generating random strings")
- for i in range(N):
- c.append(t.encrypt_block(m[i]))
- print("starting")
- """
- timeit.repeat(encrypt_check, setup=test_setup, number=1, repeat=5)
- # [0.02347087860107422, 0.02314305305480957, 0.02311396598815918, 0.022945165634155273, 0.022997140884399414]
- # 23.134 +/- 0.183 ms
- timeit.repeat(decrypt_check, setup=test_setup, number=1, repeat=5)
- # [0.023146867752075195, 0.02331399917602539, 0.023048877716064453, 0.023074865341186523, 0.023090124130249023]
- # 23.135 +/- 0.095 ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement