aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2015-04-25 16:41:11 +0200
committerCamil Staps2015-04-25 16:41:11 +0200
commitbe0183a25122d1c9aa13a352662fe0c33f9c7fc6 (patch)
tree5984b5804138712ea999b79ccdfaa15774ed8c16
parentSmaller notation for matrices (diff)
Profiling
-rwxr-xr-xtest-vectors.py77
1 files changed, 41 insertions, 36 deletions
diff --git a/test-vectors.py b/test-vectors.py
index f4d3399..55e6a26 100755
--- a/test-vectors.py
+++ b/test-vectors.py
@@ -23,47 +23,52 @@
from pypride import Pride
import time
-test_vectors = [
- {'key': "00000000000000000000000000000000", 'plaintext': "0000000000000000", 'ciphertext': "82b4109fcc70bd1f"},
- {'key': "00000000000000000000000000000000", 'plaintext': "ffffffffffffffff", 'ciphertext': "d70e60680a17b956"},
- {'key': "ffffffffffffffff0000000000000000", 'plaintext': "0000000000000000", 'ciphertext': "28f19f97f5e846a9"},
- {'key': "0000000000000000ffffffffffffffff", 'plaintext': "0000000000000000", 'ciphertext': "d123ebaf368fce62"},
- {'key': "0000000000000000fedcba9876543210", 'plaintext': "0123456789abcdef", 'ciphertext': "d1372929712d336e"}
-]
+def test():
+ test_vectors = [
+ {'key': "00000000000000000000000000000000", 'plaintext': "0000000000000000", 'ciphertext': "82b4109fcc70bd1f"},
+ {'key': "00000000000000000000000000000000", 'plaintext': "ffffffffffffffff", 'ciphertext': "d70e60680a17b956"},
+ {'key': "ffffffffffffffff0000000000000000", 'plaintext': "0000000000000000", 'ciphertext': "28f19f97f5e846a9"},
+ {'key': "0000000000000000ffffffffffffffff", 'plaintext': "0000000000000000", 'ciphertext': "d123ebaf368fce62"},
+ {'key': "0000000000000000fedcba9876543210", 'plaintext': "0123456789abcdef", 'ciphertext': "d1372929712d336e"}
+ ]
-time_cipher = 0
-time_encrypt = 0
-time_decrypt = 0
+ time_cipher = 0
+ time_encrypt = 0
+ time_decrypt = 0
-all_passed = True
+ all_passed = True
-for v_i, vector in enumerate(test_vectors):
- key = vector['key'].decode('hex')
- start = time.time()
- cipher = Pride(key)
- time_cipher += time.time() - start
+ for _ in xrange(100):
+ for v_i, vector in enumerate(test_vectors):
+ key = vector['key'].decode('hex')
+ start = time.time()
+ cipher = Pride(key)
+ time_cipher += time.time() - start
- plaintext = vector['plaintext'].decode('hex')
- start = time.time()
- encryption = cipher.encrypt(plaintext)
- time_encrypt += time.time() - start
+ plaintext = vector['plaintext'].decode('hex')
+ start = time.time()
+ encryption = cipher.encrypt(plaintext)
+ time_encrypt += time.time() - start
- ciphertext = vector['ciphertext'].decode('hex')
- start = time.time()
- decryption = cipher.decrypt(ciphertext)
- time_decrypt += time.time() - start
-
- if encryption != vector['ciphertext'].decode('hex'):
- print "Encryption for vector", v_i, "failed: was", encryption.encode('hex'), "; should have been", vector['ciphertext']
- all_passed = False
+ ciphertext = vector['ciphertext'].decode('hex')
+ start = time.time()
+ decryption = cipher.decrypt(ciphertext)
+ time_decrypt += time.time() - start
+
+ if encryption != vector['ciphertext'].decode('hex'):
+ print "Encryption for vector", v_i, "failed: was", encryption.encode('hex'), "; should have been", vector['ciphertext']
+ all_passed = False
- if decryption != vector['plaintext'].decode('hex'):
- print "Decryption for vector", v_i, "failed: was", decryption.encode('hex'), "; should have been", vector['plaintext']
- all_passed = False
+ if decryption != vector['plaintext'].decode('hex'):
+ print "Decryption for vector", v_i, "failed: was", decryption.encode('hex'), "; should have been", vector['plaintext']
+ all_passed = False
-if all_passed:
- print "All tests passed."
+ if all_passed:
+ print "All tests passed."
-print "Generating round keys:", str(time_cipher) + "s"
-print "Encryption: ", str(time_encrypt) + "s"
-print "Decryption: ", str(time_decrypt) + "s" \ No newline at end of file
+ print "Generating round keys:", str(time_cipher) + "s"
+ print "Encryption: ", str(time_encrypt) + "s"
+ print "Decryption: ", str(time_decrypt) + "s"
+
+import profile
+profile.run('test()') \ No newline at end of file