Guest User

threefish in python3 timing, encryption/decryption

a guest
Jun 28th, 2013
154
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import timeit
  2.  
  3. encrypt_check = "print(all(c[i] == t.encrypt_block(m[i]) for i in range(N)))"
  4.  
  5. decrypt_check = "print(all(m[i] == t.decrypt_block(c[i]) for i in range(N)))"
  6.  
  7. test_setup = """
  8. from skein import threefish
  9. import hashlib
  10. import string
  11. import random
  12. key = hashlib.sha512(b'password').digest() # 64 byte key (512 bits)
  13. tweak = b'This is my tweak'
  14. t = threefish(key, tweak)
  15. m = []
  16. c = []
  17. N = 50000
  18. for i in range(N):
  19.    m.append(bytes("".join(random.choice(string.printable) for i in range(64)), encoding='utf8'))
  20. print("Done generating random strings")
  21. for i in range(N):
  22.    c.append(t.encrypt_block(m[i]))
  23. print("starting")
  24. """
  25.  
  26. timeit.repeat(encrypt_check, setup=test_setup, number=1, repeat=5)
  27. # [0.02347087860107422, 0.02314305305480957, 0.02311396598815918, 0.022945165634155273, 0.022997140884399414]
  28. # 23.134 +/- 0.183 ms
  29.  
  30. timeit.repeat(decrypt_check, setup=test_setup, number=1, repeat=5)
  31. # [0.023146867752075195, 0.02331399917602539, 0.023048877716064453, 0.023074865341186523, 0.023090124130249023]
  32. # 23.135 +/- 0.095 ms
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×