-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathhashing.py
76 lines (60 loc) · 2.02 KB
/
hashing.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import hashlib
from optparse import *
class colors:
def __init__(self):
self.blue = "\033[94m"
self.red = "\033[91m"
self.end = "\033[0m"
cl = colors()
print(cl.blue+"""
*--------------------------------------*
| programmed by : mohamed |
| fb.me/hack1lab |
*--------------------------------------*
_ _ _ _
| |__ __ _ ___| | _| | __ _| |__
| '_ \ / _` |/ __| |/ / |/ _` | '_ \
| | | | (_| | (__| <| | (_| | |_) |
|_| |_|\__,_|\___|_|\_\_|\__,_|_.__/
hashing
---------
"""+cl.end)
def hashing(data, type_h):
hash_type = hashlib.new(type_h)
hash_type.update(data)
return hash_type.hexdigest()
parser = OptionParser("""
-------------------------[Usage]------------------------
#Options:
-x hashing text
-f hashing file any file e.g (.txt, .rar, .zip, .iso, .exe, .py, ........ etc)
-t the Hashing type e.g (md5, md4, sha1, sha256, sha512, ....... etc)
#Example:
python hashing.py -x hacklab -t md5
python hashing.py -f kali_linux.iso -t sha1
""")
try:
parser.add_option("-x",dest="Text",type="string", help="enter text for hashing")
parser.add_option("-f",dest="File",type="string", help="enter file for hahsing")
parser.add_option("-t",dest="Type",type="string", help="Enter the Hashing type")
(options, args) = parser.parse_args()
if options.Text == None and options.File == None:
print(cl.blue+parser.usage+cl.end)
exit(0)
else:
Text = str(options.Text)
File = str(options.File)
Type = str(options.Type)
if options.Text == None:
read_file = open(File, 'r')
File = str(read_file.read())
result = hashing(File, Type)
print(cl.red+"[+] Hash File: [ "+result+' ]'+cl.end+'\n')
elif options.File == None:
result = hashing(Text,Type)
print(cl.red+"[+] Hash Text: [ "+result+' ]'+cl.end+'\n')
else:
print(cl.blue+"[-] there error !!"+cl.end)
except Exception, e:
print("Error: "+ str(e))