Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Dissertation_sourcecode/3DES-decrypt.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 lines (19 sloc)
894 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from Crypto.Cipher import DES3 | |
from Crypto.Util.Padding import unpad | |
import time | |
# random generation of keys and iv | |
key = b'TWENTYFOURBYTEKEY3DES$$$' | |
iv = b'IVIVIVIV' | |
size_handling = [100000, 500000, 1000000, 5000000, 10000000] | |
for i in size_handling: | |
ciphertext = b'\x04\x88o\xcb$\xd9\xfe\xc2?\x1e\xc2\xc2\x17(\xe6{\xe6\xd3\x07}!\x0f\xef\xbe\xc4\x16\x0e\x9cC\x85\x05\x1b\xd4\xe5\x01\xf2\xaaa\\\xc3\x89BZQ[9K ' * i | |
t1 = time.time() | |
# create cipher object with triple DES algorithm in CBC mode | |
cipher = DES3.new(key, DES3.MODE_CBC, iv) | |
# decrypt the ciphertext | |
decrypted_padding = cipher.decrypt(ciphertext) # decryption | |
plaintext = unpad(decrypted_padding, DES3.block_size) #remove padding | |
t2 = time.time() | |
t3 = t2 - t1 #total time to decrypt according to file size | |
print(f'time taken to decrypt:{t3} for size bytes:{i}') |