-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsatime.py
37 lines (31 loc) · 1.11 KB
/
rsatime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import time
from cryptography.fernet import Fernet
# Generate a key
key = Fernet.generate_key()
# Encrypt a file and measure time taken
def encrypt_file(infile, outfile, key):
f = Fernet(key)
with open(infile, "rb") as fin:
data = fin.read()
start_time = time.time()
encrypted_data = f.encrypt(data)
end_time = time.time()
with open(outfile, "wb") as fout:
fout.write(encrypted_data)
return end_time - start_time
# Decrypt a file and measure time taken
def decrypt_file(infile, outfile, key):
f = Fernet(key)
with open(infile, "rb") as fin:
encrypted_data = fin.read()
start_time = time.time()
decrypted_data = f.decrypt(encrypted_data)
end_time = time.time()
with open(outfile, "wb") as fout:
fout.write(decrypted_data)
return end_time - start_time
# Encrypt and decrypt a file and measure time taken
encryption_time = encrypt_file("btpsem6.txt", "encrypted.bin", key)
print(f"Encryption time: {encryption_time} seconds")
decryption_time = decrypt_file("encrypted.bin", "decrypted.txt", key)
print(f"Decryption time: {decryption_time} seconds")