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/blowfish2.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (20 sloc)
835 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 | |
import time | |
from Crypto.Cipher import Blowfish | |
from Crypto.Util.Padding import pad | |
# define key and IV | |
key = b'KEYKEYKE' | |
iv = b'IVIVIVIV' | |
# define data sizes to test | |
size_handling = [100000, 500000, 1000000 ,5000000,10000000] | |
# iterate over data sizes and test encryption time and data handling | |
for i in size_handling: | |
message = b'Which witch switched the Swiss wristwatches?' * i | |
start_time = time.time() | |
# create cipher object with Blowfish algorithm in CBC mode | |
cipher = Blowfish.new(key, Blowfish.MODE_CBC, iv) | |
padding = pad(message, Blowfish.block_size) #additional padding | |
ciphertext = cipher.encrypt(padding)# encrypting data | |
end_time = time.time() | |
total_time = end_time - start_time | |
print(f"Encryption time: {total_time} seconds for encrypted bytes: {i}") |