Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/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}') |
25
3DES.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/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") |
23
AES-128.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
from Crypto.Cipher import AES | ||
import os | ||
import time | ||
|
||
key = os.urandom(16) | ||
iv = os.urandom(16) | ||
# Create an AES-128 cipher object with the key and IV | ||
cipher = AES.new(key, AES.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 | ||
|
||
initial_time = time.time() | ||
ciphertext = cipher.encrypt(message) #encrypts secret message | ||
end_time = time.time() | ||
total_time = end_time - initial_time #total time taken to encrypt | ||
|
||
print(f"time taken for secret message * {i} encryption bytes: {total_time} seconds") | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
from Crypto.Cipher import AES | ||
import os | ||
import time | ||
|
||
key = os.urandom(16) | ||
iv = os.urandom(16) | ||
# Create an AES-128 cipher object with the key and IV | ||
cipher = AES.new(key, AES.MODE_CBC, iv) | ||
|
||
size_handling = [100000,500000,1000000,5000000,10000000] | ||
# Measure the time taken to encrypt encrypted_messages of increasing size | ||
for i in size_handling: | ||
encrypted_message = b'\x95lxk\xb5\xd8\xb7b9l\x153\x83}v\xceLT6U\xd6<\xf3\x92&\xb9P\x8a\x0f\xa1\xc9\x90+0\xb3zC\xbf\xa0\x89\xbf\xbb\xb5\xa8\x801c\x8d' * i | ||
|
||
initial_time = time.time() | ||
plaintext = cipher.decrypt(encrypted_message) #decrypts message | ||
end_time = time.time() | ||
total_time = end_time - initial_time #total time taken to decrypt | ||
|
||
print(f"time taken for encrypted message to decrypt * {i} bytes: {total_time} seconds") | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
from Crypto.Cipher import Blowfish | ||
from Crypto.Util.Padding import unpad | ||
import time | ||
|
||
# define key and IV | ||
key = b'KEYKEYKE' | ||
iv = b'IVIVIVIV' | ||
|
||
size_handling = [100000, 500000, 1000000 ,5000000,10000000] | ||
|
||
for i in size_handling: | ||
ciphertext = b'\xbf\x92\xfd\x9eV\xa7uU\xb7A\x87\xec_\xf0\xa7\xe7\x06k\xb5\x98\x89\xeb`\xaf2\x7f\xe3\xa2\x08z\x8f\xd9\x97\xd9$"\x9d\x15?\x05\xf0P@\x90B\xb9\x9a;' * i | ||
t1 = time.time() | ||
# create cipher object with Blowfish algorithm in CBC mode | ||
cipher = Blowfish.new(key, Blowfish.MODE_CBC, iv) | ||
|
||
# decrypt the ciphertext | ||
decrypted_padding = cipher.decrypt(ciphertext) # decryption | ||
plaintext = unpad(decrypted_padding, Blowfish.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}') | ||
|
28
blowfish2.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/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}") |