File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
4- __author__ = ' ipetrash'
4+ __author__ = " ipetrash"
55
66
77import hashlib
88import sys
99
10- if __name__ == '__main__' :
11- algorithms = list (hashlib .algorithms_available ) # get list algorithms
12- algorithms .sort ()
13- print ("Algorithms available: %s" % ", " .join (algorithms ))
14-
15- text = input ("Text: " )
16- if not text :
17- print ("Empty text!" )
18- sys .exit (1 )
19-
20- alg_name = input ("Name algorithm: " )
21- if alg_name not in algorithms : # search in list
22- print ("Algorithm not found!" )
23- sys .exit (1 )
24-
25- alg = hashlib .new (alg_name ) # create hash function from name
26- alg .update (text .encode ()) # set data in hash-function
27- print ("Result:" )
28- print (" hex: %s" % alg .hexdigest ())
29- print (" HEX: %s" % alg .hexdigest ().upper ())
10+
11+ algorithms = list (hashlib .algorithms_available ) # get list algorithms
12+ algorithms .sort ()
13+ print (f "Algorithms available: { ', ' .join (algorithms )} " )
14+
15+ text = input ("Text: " )
16+ if not text :
17+ print ("Empty text!" )
18+ sys .exit (1 )
19+
20+ alg_name = input ("Name algorithm: " )
21+ if alg_name not in algorithms : # search in list
22+ print ("Algorithm not found!" )
23+ sys .exit (1 )
24+
25+ alg = hashlib .new (alg_name ) # create hash function from name
26+ alg .update (text .encode ()) # set data in hash-function
27+ print ("Result:" )
28+ print (f " hex: { alg .hexdigest ()} " )
29+ print (f " HEX: { alg .hexdigest ().upper ()} " )
Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
4- __author__ = ' ipetrash'
4+ __author__ = " ipetrash"
55
66
7+ import hashlib
78from datetime import datetime
8- import hashlib
99
1010
11- if __name__ == '__main__' :
12- ts = datetime .today ().timestamp ()
13- bts = str (ts ).encode ()
11+ ts = datetime .today ().timestamp ()
12+ bts = str (ts ).encode ()
1413
15- # Long
16- md5 = hashlib .md5 ()
17- md5 .update (bts )
14+ # Long
15+ md5 = hashlib .md5 ()
16+ md5 .update (bts )
1817
19- print (md5 .hexdigest ())
20-
21- # Short
22- print (hashlib .md5 (bts ).hexdigest ())
18+ print (md5 .hexdigest ())
2319
20+ # Short
21+ print (hashlib .md5 (bts ).hexdigest ())
Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
4- __author__ = ' ipetrash'
4+ __author__ = " ipetrash"
55
66
77import hashlib
88
9- if __name__ == '__main__' :
10- available = list (set (map (str .lower , hashlib .algorithms_available )))
11- available .sort ()
129
13- text = 'hello world'
10+ available = list (set (map (str .lower , hashlib .algorithms_available )))
11+ available .sort ()
1412
15- for algo_name in available :
16- try :
17- alg = hashlib .new (algo_name ) # create hash function from name
18- alg .update (text .encode ()) # set data in hash-function
19- print ("{}: {}" .format (algo_name , alg .hexdigest ().upper ()))
13+ text = "hello world"
2014
21- except ValueError :
22- pass
15+ for algo_name in available :
16+ try :
17+ alg = hashlib .new (algo_name ) # create hash function from name
18+ alg .update (text .encode ()) # set data in hash-function
19+ print (f"{ algo_name } : { alg .hexdigest ().upper ()} " )
20+
21+ except ValueError :
22+ pass
Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
4- __author__ = ' ipetrash'
4+ __author__ = " ipetrash"
55
66
7- def to_sha256 (text ):
8- import hashlib
7+ import hashlib
8+
9+
10+ def to_sha256 (text : str ) -> str :
911 return hashlib .sha256 (text .encode ()).hexdigest ()
1012
1113
12- if __name__ == ' __main__' :
13- print (to_sha256 (' Hello World!' ))
14+ if __name__ == " __main__" :
15+ print (to_sha256 (" Hello World!" ))
You can’t perform that action at this time.
0 commit comments