8
8
safelock_cmd = "safelock-cli"
9
9
pwd = "123456789"
10
10
rest = "60s"
11
- input_path = "test "
11
+ input_path = "~/Videos "
12
12
output_name = "test"
13
13
output_dir = "safelock_dump"
14
14
runs = 3
15
15
figure_width = 14
16
- figure_height = 2.5
16
+ figure_height = 3
17
17
bar_width = 0.6
18
18
measure = "Seconds"
19
19
root = os .getcwd ()
20
20
21
+ def get_label (i , clean = False , key = "command" ):
22
+ matchers = [
23
+ ('gpg' , 'gpgtar' ,),
24
+ ('7z' , '7zip (fastest)' ,),
25
+ ('256' , 'safelock --sha256' ,),
26
+ ('512' , 'safelock --sha512' ,),
27
+ ('safelock' , 'safelock' ,),
28
+ ]
29
+ label = next ((v for m , v in matchers if m in i [key ]))
30
+
31
+ if clean :
32
+ return label
33
+ if key == "label" :
34
+ return f"{ label } \n { i ['size' ]:.2f} MB"
35
+
36
+ return f"{ label } \n { i ['median' ]:.3f} s"
37
+
38
+ def get_name (i ):
39
+ matchers = [
40
+ ('gpg' , f'{ output_name } .gpg' ,),
41
+ ('7z' , f'{ output_name } .7z' ,),
42
+ ('256' , f'{ output_name } _sha256.sla' ,),
43
+ ('512' , f'{ output_name } _sha512.sla' ,),
44
+ ('safelock' , f'{ output_name } .sla' ,),
45
+ ]
46
+
47
+ return next ((v for m , v in matchers if m in i ))
48
+
21
49
def encrypt ():
22
50
err = os .system (
23
51
f"hyperfine --runs { runs } --prepare "
24
52
f"'sleep { rest } ' "
25
- f"'echo \" { pwd } \" | { safelock_cmd } encrypt { input_path } { output_name } .sla --quiet' "
26
- f"'echo \" { pwd } \" | { safelock_cmd } encrypt { input_path } { output_name } _sha256.sla --quiet --sha256' "
27
- f"'echo \" { pwd } \" | { safelock_cmd } encrypt { input_path } { output_name } _sha512.sla --quiet --sha512' "
28
- f"'gpgtar -e -o test.gpg -c --yes --batch --gpg-args \" --passphrase { pwd } \" Videos/' "
53
+ f"'echo \" { pwd } \" | { safelock_cmd } encrypt { input_path } { get_name ('safelock' )} --quiet' "
54
+ f"'echo \" { pwd } \" | { safelock_cmd } encrypt { input_path } { get_name ('256' )} --quiet --sha256' "
55
+ f"'echo \" { pwd } \" | { safelock_cmd } encrypt { input_path } { get_name ('512' )} --quiet --sha512' "
56
+ f"'7z a -p{ pwd } -mx1 { get_name ('7z' )} { input_path } ' "
57
+ f"'gpgtar -e -o { get_name ('gpg' )} -c --yes --batch --gpg-args \" --passphrase { pwd } \" Videos/' "
29
58
f"--export-json { root } /encryption.json"
30
59
)
31
60
@@ -35,38 +64,26 @@ def encrypt():
35
64
def decrypt ():
36
65
err = os .system (
37
66
f"hyperfine --runs { runs } --prepare "
38
- f"'rm -rf { output_dir } { output_name } _1_ && mkdir { output_dir } && sleep { rest } ' "
39
- f"'echo \" { pwd } \" | { safelock_cmd } decrypt { output_name } .sla { output_dir } --quiet' "
40
- f"'echo \" { pwd } \" | { safelock_cmd } decrypt { output_name } _sha256.sla { output_dir } --quiet --sha256' "
41
- f"'echo \" { pwd } \" | { safelock_cmd } decrypt { output_name } _sha512.sla { output_dir } --quiet --sha512' "
42
- f"'gpgtar -d --yes --batch --gpg-args \" --passphrase { pwd } \" test.gpg' "
67
+ f"'rm -rf { output_dir } { output_name } _*_ && mkdir { output_dir } && sleep { rest } ' "
68
+ f"'echo \" { pwd } \" | { safelock_cmd } decrypt { get_name ('safelock' )} { output_dir } --quiet' "
69
+ f"'echo \" { pwd } \" | { safelock_cmd } decrypt { get_name ('256' )} { output_dir } --quiet --sha256' "
70
+ f"'echo \" { pwd } \" | { safelock_cmd } decrypt { get_name ('512' )} { output_dir } --quiet --sha512' "
71
+ f"'7z e -y -p{ pwd } -mx1 { get_name ('7z' )} -o{ output_dir } ' "
72
+ f"'gpgtar -d --yes --batch --gpg-args \" --passphrase { pwd } \" { get_name ('gpg' )} ' "
43
73
f"--export-json { root } /decryption.json"
44
74
)
45
75
46
76
if err :
47
77
exit (err )
48
78
49
- def get_label (i , clean = False ):
50
- label = i ['command' ]
51
-
52
- if 'gpg' in label :
53
- label = 'gpgtar'
54
- elif 'sha256' in label :
55
- label = 'safelock --sha256'
56
- elif 'sha512' in label :
57
- label = 'safelock --sha512'
58
- else :
59
- label = 'safelock'
60
-
61
- if clean :
62
- return label
63
-
64
- return f"{ label } \n { i ['median' ]:.3f} s"
65
-
66
- # os.chdir(os.path.expanduser("~"))
79
+ os .chdir (os .path .expanduser ("~" ))
67
80
# encrypt()
68
81
# decrypt()
69
82
os .chdir (root )
83
+ plt .margins (3.5 )
84
+
85
+
86
+ # Encryption Time Plot
70
87
71
88
with open ("encryption.json" ) as f :
72
89
data = sorted (json .load (f )['results' ], key = lambda i : i ['median' ])
@@ -75,8 +92,6 @@ def get_label(i, clean=False):
75
92
colors_map = {get_label (i , 1 ): random .choice (list (plot_colors .values ())) for i in data }
76
93
colors = [colors_map [get_label (i , 1 )] for i in data ]
77
94
78
- plt .margins (3.5 )
79
-
80
95
fig , ax = plt .subplots ()
81
96
ax .set_title ('Encryption Time' )
82
97
ax .set_xlabel (measure )
@@ -85,6 +100,9 @@ def get_label(i, clean=False):
85
100
fig .tight_layout ()
86
101
fig .savefig ("encryption-time.webp" , transparent = True , format = "webp" )
87
102
103
+
104
+ # Decryption Time Plot
105
+
88
106
with open ("decryption.json" ) as f :
89
107
data = sorted (json .load (f )['results' ], key = lambda i : i ['median' ])
90
108
labels = [get_label (i ) for i in data ]
@@ -98,3 +116,25 @@ def get_label(i, clean=False):
98
116
fig .set_size_inches (w = figure_width , h = figure_height )
99
117
fig .tight_layout ()
100
118
fig .savefig ("decryption-time.webp" , transparent = True , format = "webp" )
119
+
120
+
121
+ # File Sizes Plot
122
+
123
+ os .chdir (os .path .expanduser ("~" ))
124
+ data = sorted ([{
125
+ 'size' : os .path .getsize (get_name (get_label (i ))) / 1024 / 1024 ,
126
+ 'label' : get_label (i ),
127
+ 'color' : colors_map [get_label (i , 1 )],
128
+ } for i in data ], key = lambda i : i ['size' ])
129
+ os .chdir (root )
130
+ labels = [get_label (i , key = 'label' ) for i in data ]
131
+ sizes = [i ['size' ] for i in data ]
132
+ colors = [i ['color' ] for i in data ]
133
+
134
+ fig , ax = plt .subplots ()
135
+ ax .set_title ('File Size' )
136
+ ax .set_xlabel ("Megabytes" )
137
+ ax .barh (labels , sizes , bar_width , color = colors )
138
+ fig .set_size_inches (w = figure_width , h = figure_height )
139
+ fig .tight_layout ()
140
+ fig .savefig ("file-size.webp" , transparent = True , format = "webp" )
0 commit comments