This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

threefish in python3 timing, encryption/decryption

By: a guest on Jun 28th, 2013  |  syntax: Python  |  size: 1.05 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data