aboutsummaryrefslogtreecommitdiff
path: root/test-vectors.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-vectors.py')
-rwxr-xr-xtest-vectors.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/test-vectors.py b/test-vectors.py
index 55e6a26..a6bcae8 100755
--- a/test-vectors.py
+++ b/test-vectors.py
@@ -22,14 +22,15 @@
from pypride import Pride
import time
+import binascii
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"}
+ {'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
@@ -38,37 +39,37 @@ def test():
all_passed = True
- for _ in xrange(100):
+ for _ in range(100):
for v_i, vector in enumerate(test_vectors):
- key = vector['key'].decode('hex')
+ key = binascii.unhexlify(vector['key'])
start = time.time()
cipher = Pride(key)
time_cipher += time.time() - start
- plaintext = vector['plaintext'].decode('hex')
+ plaintext = binascii.unhexlify(vector['plaintext'])
start = time.time()
encryption = cipher.encrypt(plaintext)
time_encrypt += time.time() - start
- ciphertext = vector['ciphertext'].decode('hex')
+ ciphertext = binascii.unhexlify(vector['ciphertext'])
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']
+ if encryption != binascii.unhexlify(vector['ciphertext']):
+ print('Encryption for vector ' + str(v_i) + ' failed: was ' + str(binascii.hexlify(encryption)) + '; 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']
+ if decryption != binascii.unhexlify(vector['plaintext']):
+ print('Decryption for vector ' + str(v_i) + ' failed: was ' + str(binascii.hexlify(decryption)) + '; should have been ' + vector['plaintext'])
all_passed = False
if all_passed:
- print "All tests 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"
+ 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
+profile.run('test()')