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.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
25 lines (20 sloc)
824 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 pad | |
import os | |
import time | |
# generation of keys and iv | |
key = b'TWENTYFOURBYTEKEY3DES$$$' | |
iv = b'IVIVIVIV' | |
# Create a 3DES cipher object with the key and IV | |
cipher = DES3.new(key, DES3.MODE_CBC, iv) | |
size_handling = [100000, 500000, 1000000, 5000000, 10000000] | |
# Measure the time taken to encrypt messages of increasing size | |
for i in size_handling: | |
message = b'Which witch switched the Swiss wristwatches?' * i | |
t1 = time.time() | |
padding = pad(message, DES3.block_size) #additional padding | |
ciphertext = cipher.encrypt(message) # encrypts secret message | |
t2 = time.time() | |
total_time = t2 - t1 # total time taken to encrypt | |
print(f"time taken for secret message * {i} encryption bytes: {total_time} seconds") |