-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.py
41 lines (30 loc) · 845 Bytes
/
hash.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
38
39
40
41
"""
[hash.py]
Provides the `hash` function, with various tools for hashing.
"""
import hashlib
def md5(string):
m = hashlib.md5()
m.update(string)
return m.digest()
def sha256(string):
s = hashlib.sha256()
s.update(string)
return s.digest()
def hash(argc):
"""hash: various hashing functions.
Usage:
hash (md5|sha256) FILE
hash (md5|sha256) --string STRING
"""
if argc.args['FILE']:
if argc.args['md5']:
return md5(open(argc.args['FILE']).read())
elif argc.args['sha256']:
return sha256(open(argc.args['FILE']).read())
elif argc.args['--string']:
if argc.args['md5']:
return md5(argc.args['STRING'])
elif argc.args['sha256']:
return sha256(argc.args['STRING'])
exports = {"hash": hash}