1+ # coding=utf-8
12from PasswordBase .base_reader import decrypt_base_password , read_password_base
23from PasswordBase .base_writer import writeNewBase
34from PasswordConvertion .convertion import encrypt_to_sha256 , encrypt_to_sha1 , encrypt_to_md5
89base_file_path = './PasswordBase/'
910
1011
11- def countTime ( hashName , converstionFunc ):
12+ def count_time ( hash_name , converstion_func ):
1213 start_time = time .time ()
1314 base_list = read_password_base (base_file_path + 'base.txt' )
1415 list = decrypt_base_password (base_list )
15- convert_list (list , converstionFunc , hashName )
16+ convert_list (list , converstion_func , hash_name )
1617 timeUsed = (time .time () - start_time )
17- # print("TIMEUSED %s --- %s seconds ---" % (hashName, timeUsed))
1818 return timeUsed
1919
20+ times = 50
2021
21- def convert_list (list , convertionFunc , hashName ):
22+ def convert_list (list , convertion_func , hash_hame ):
2223 for line in list :
23- line [1 ] = convertionFunc (line [1 ])
24- writeNewBase (base_file_path + 'base_' + hashName + '.txt' , list )
24+ line [1 ] = convertion_func (line [1 ])
25+ writeNewBase (base_file_path + 'base_' + hash_hame + '.txt' , list )
2526
2627
2728def reportMD5 ():
2829 md5Times = []
29- for x in range (0 , 10 ):
30- md5Times .append (countTime ('md5' , encrypt_to_md5 ))
30+ for x in range (0 , times ):
31+ md5Times .append (count_time ('md5' , encrypt_to_md5 ))
3132
3233 report ('MD5' , md5Times )
33- # print md5Times
34- # mean = np.average(md5Times)
35- # print("Mean %s --- %s seconds ---" % ('md5', mean))
3634 return md5Times
3735
3836
3937def reportSHA1 ():
4038 sha1Times = []
41- for x in range (0 , 10 ):
42- sha1Times .append (countTime ('sha1' , encrypt_to_sha1 ))
39+ for x in range (0 , times ):
40+ sha1Times .append (count_time ('sha1' , encrypt_to_sha1 ))
4341
4442 report ('SHA1' , sha1Times )
45- # print md5Times
46- # mean = np.average(sha1Times)
47- # print mean
48- # print("Mean %s --- %s seconds ---" % ('sha1', mean))
4943 return sha1Times
5044
5145
5246def reportSHA256 ():
5347 sha256Times = []
54- for x in range (0 , 10 ):
55- sha256Times .append (countTime ('sha256' , encrypt_to_sha256 ))
48+ for x in range (0 , times ):
49+ sha256Times .append (count_time ('sha256' , encrypt_to_sha256 ))
5650
5751 report ('SHA256' , sha256Times )
5852 return sha256Times
5953
6054
6155def report (name , array ):
62- mean = np .average (array )
63- min = np .amin (array )
64- max = np .amax (array )
6556 var = np .var (array )
66- dp = np .sqrt (var )
6757
68- print ("Mean %s --- %s seconds ---" % (name , mean ))
69- print ("Min %s --- %s seconds ---" % (name , min ))
70- print ("Max %s --- %s seconds ---" % (name , max ))
58+ print ("Mean %s --- %s seconds ---" % (name , np . average ( array ) ))
59+ print ("Min %s --- %s seconds ---" % (name , np . amin ( array ) ))
60+ print ("Max %s --- %s seconds ---" % (name , np . amax ( array ) ))
7161 print ("Var %s --- %s seconds ---" % (name , var ))
72- print ("DP %s --- %s seconds ---" % (name , dp ))
62+ print ("DP %s --- %s seconds ---" % (name , np . sqrt ( var ) ))
7363
7464
7565def ploting (x1 , x2 , x3 ):
76- plt .plot (x1 , 'r--' , marker = 'o' , label = 'MD5' )
77- plt .plot (x2 , 'b--' , marker = 'o' , label = 'SHA1' )
78- plt .plot (x3 , 'g--' , marker = 'o' , label = 'SHA256' )
66+ plt .plot (x1 , 'r--' , label = 'MD5' )
67+ plt .plot (x2 , 'b--' , label = 'SHA1' )
68+ plt .plot (x3 , 'g--' , label = 'SHA256' )
7969
8070 plt .legend (bbox_to_anchor = (0. , 1.02 , 1. , .102 ), loc = 3 ,
8171 ncol = 2 , mode = "expand" , borderaxespad = 0. )
@@ -90,5 +80,3 @@ def ploting(x1, x2, x3):
9080x3 = reportSHA256 ()
9181
9282ploting (x1 , x2 , x3 )
93-
94- # http://stackoverflow.com/questions/20412038/printing-python-code-to-pdf OLHAR
0 commit comments