You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pyFileFixity/ecc_speedtest.py
+27-23Lines changed: 27 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@
31
31
sys.path.append(os.path.join(thispathname))
32
32
33
33
# ECC and hashing facade libraries
34
-
fromlib._compatimport_range
34
+
fromlib._compatimport_range, _bytes
35
35
fromlib.aux_funcsimportsizeof_fmt
36
36
fromlib.eccmanimportECCMan, compute_ecc_params
37
37
fromlib.hasherimportHasher
@@ -70,7 +70,7 @@ def main(argv=None):
70
70
msg_nb=1000000
71
71
tamper_rate=0.4# tamper rate is relative to the number of ecc bytes, not the whole message (not like the resilience_rate)
72
72
tamper_mode='noise'# noise or erasure
73
-
no_decoding=True
73
+
no_decoding=False# True for only encoding, False for both encoding then decoding, 3 for only decoding (which includes an encoding step)
74
74
subchunking=False
75
75
subchunk_size=50
76
76
@@ -86,33 +86,37 @@ def main(argv=None):
86
86
print("ECC Speed Test, started on %s"%datetime.datetime.now().isoformat())
87
87
print("====================================")
88
88
print("ECC algorithm: %i."%ecc_algo)
89
+
print("%s."% ("Only encoding test"ifno_decodingisTrueelse ("Encoding and decoding test"ifno_decodingisFalseelse"Decoding test only (including an encoding step)")))
89
90
90
91
# -- Encoding test
91
92
# IMPORTANT: we do NOT check the correctness of encoding, only the speed! It's up to you to verify that you are computing the ecc correctly.
92
-
total_time=0
93
-
total_size=msg_nb*max_block_size
94
-
bardisp=tqdm.tqdm(total=total_size, leave=True, desc='ENC', unit='B', unit_scale=True, ncols=79, mininterval=0.5) # display progress bar based on the number of bytes encoded
95
-
k=ecc_params["message_size"]
96
-
# Generate a random string and encode it
97
-
formsgingen_random_string(msg_nb, k):
98
-
start=time.process_time() # time.clock() was dropped in Py3.8, use time.perf_counter() instead to time performance including sleep, or time.process_time() without sleep periods.
print("Encoding: total time elapsed: %f sec for %s of data. Real Speed (only encoding, no other computation): %s."% (total_time, format_sizeof(total_size, 'B'), format_sizeof(total_size/total_time, 'B/sec') ))
93
+
ifnotno_decoding==3:
94
+
total_time=0
95
+
total_size=msg_nb*max_block_size
96
+
bardisp=tqdm.tqdm(total=total_size, leave=True, desc='ENC', unit='B', unit_scale=True, ncols=79, mininterval=0.5) # display progress bar based on the number of bytes encoded
97
+
k=ecc_params["message_size"]
98
+
# Generate a random string and encode it
99
+
formsgingen_random_string(msg_nb, k):
100
+
start=time.process_time() # time.clock() was dropped in Py3.8, use time.perf_counter() instead to time performance including sleep, or time.process_time() without sleep periods.
print("Encoding: total time elapsed: %f sec for %s of data. Real Speed (only encoding, no other computation): %s."% (total_time, format_sizeof(total_size, 'B'), format_sizeof(total_size/total_time, 'B/sec') ))
108
110
109
111
# -- Decoding test
110
-
ifnotno_decoding:
112
+
ifnotno_decodingorno_decoding==3:
111
113
total_time=0
112
114
total_size=msg_nb*max_block_size
113
-
bardisp=tqdm.tqdm(total=total_size, leave=True, desc='ENC', unit='B', unit_scale=True) # display progress bar based on the number of bytes encoded
115
+
bardisp=tqdm.tqdm(total=total_size*2, leave=True, desc='DEC', unit='B', unit_scale=True) # display progress bar based on the number of bytes encoded
eliftamper_mode=='e'ortamper_mode=='erasure': # Erase the character (set a null byte)
129
133
msg_tampered[pos] =0
130
134
# Convert back to a string
131
-
msg_tampered=str(msg_tampered)
132
-
ecc=str(ecc)
135
+
msg_tampered=_bytes(msg_tampered)
136
+
ecc=_bytes(ecc)
133
137
134
138
# Decode the tampered message with ecc
135
139
start=time.process_time()
@@ -141,7 +145,7 @@ def main(argv=None):
141
145
print("Warning, there was an error while decoding. Please check your parameters (tamper_rate not too high) or the decoding procedure.")
142
146
pass
143
147
total_time+=time.process_time() -start
144
-
bardisp.update(max_block_size)
148
+
bardisp.update(max_block_size*2) # update x2 because we encode AND decode
145
149
bardisp.close()
146
150
print("Decoding: total time elapsed: %f sec for %s of data. Real Speed (only decoding, no other computation): %s."% (total_time, format_sizeof(total_size, 'B'), format_sizeof(total_size/total_time, 'B/sec') ))
0 commit comments