-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_calculator.py
146 lines (114 loc) · 5.64 KB
/
hash_calculator.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import hashlib
from tkinter import *
from tkinter import ttk
class HashGenerator:
def __init__(self):
"""
This is a GUI based Hash Calculator build on Python.
Developed by : Amrit Pangeni
Available at : https://github.com/amr1tpang3n1/HashCalculator_Python_GUI.git
"""
self.root = Tk()
self.root.geometry("500x300")
self.root.title("Hash Calculator")
self.root.iconbitmap("icon.ico")
self.root.resizable(0, 0)
self.root.config(background="#abcdef")
self.notebook = ttk.Notebook(self.root)
self.notebook.pack()
self.StringScan = Frame(self.notebook, width=1000, height=700, bg="#70adda")
self.FileScan = Frame(self.notebook, width=1000, height=700, bg="#70adda")
self.StringScan.pack(fill=BOTH, expand=1)
self.FileScan.pack(fill=BOTH, expand=1)
self.notebook.add(self.StringScan,
text=" String Hash Calculation ")
self.notebook.add(self.FileScan, text=" File Hash Calculation ")
# GUI FOR STRING HASH CALCULATION
label1 = Label(self.StringScan, text="Hash Type & String for Generating Hash :", bg="#abcdef",
font="cambria 14")
label1.place(x=30, y=15)
self.userInput = StringVar()
entry_box = Entry(self.StringScan, font="cambria 12", width="50", textvariable=self.userInput)
entry_box.place(x=30, y=80)
self.comboBox = ttk.Combobox(self.StringScan, values=("Sha1", "Sha2", "Md5"), state='readonly')
self.comboBox.set("Md5")
self.comboBox.place(x=30, y=50)
self.button = Button(self.StringScan, text="Generate", font="cambria 13", bg="green", fg="white",
command=self.hash_generator_string)
self.button.place(x=200, y=125)
self.TextVar = StringVar()
self.result = Label(self.StringScan, text="Hash Generated: ", bg="#abcdef", font="cambria 14")
self.result_box = Entry(self.StringScan, font="cambria 12", width="50", textvariable=self.TextVar)
# GUI FOR FILE HASH CALCULATION
label2 = Label(self.FileScan, text="Hash Type & File for Generating Hash :", bg="#abcdef",
font="cambria 14")
label2.place(x=30, y=15)
self.path = StringVar()
file_path = Entry(self.FileScan, font="cambria 12", width="50", textvariable=self.path, state="readonly")
file_path.place(x=30, y=80)
self.button1 = Button(self.FileScan, text="Browse", font="cambria 11", bg="#aaaaaa",
command=self.File_Open_Dialog)
self.button1.place(x=420, y=45)
self.comboBox1 = ttk.Combobox(self.FileScan, values=("Sha1", "Sha2", "Md5"), state='readonly')
self.comboBox1.set("Md5")
self.comboBox1.place(x=30, y=50)
self.button2 = Button(self.FileScan, text="Generate", font="cambria 13", bg="green", fg="white",
command=self.hash_generator_file)
self.button2.place(x=200, y=125)
self.resultVar = StringVar()
self.result1 = Label(self.FileScan, text="Hash Generated: ", bg="#abcdef", font="cambria 14")
self.result_box1 = Entry(self.FileScan, font="cambria 12", width="50", textvariable=self.resultVar)
self.root.mainloop()
def File_Open_Dialog(self):
from tkinter import filedialog
file = filedialog.askopenfilename()
self.path.set(file)
def hash_generator_string(self):
from tkinter import messagebox
hashType = self.comboBox.get()
string = str(self.userInput.get())
if string == "":
messagebox.showinfo("Error", "Nothing to do")
elif hashType.strip() == "Md5":
password = string.encode()
passwordHash = hashlib.md5(password).hexdigest()
self.result.place(x=30, y=180)
self.TextVar.set(passwordHash)
self.result_box.place(x=30, y=220)
elif hashType.strip() == "Sha2":
password = string.encode()
passwordHash = hashlib.sha256(password).hexdigest()
self.result.place(x=30, y=180)
self.TextVar.set(passwordHash)
self.result_box.place(x=30, y=220)
elif hashType.strip() == "Sha1":
password = string.encode()
passwordHash = hashlib.sha1(password).hexdigest()
self.result.place(x=30, y=180)
self.TextVar.set(passwordHash)
self.result_box.place(x=30, y=220)
def hash_generator_file(self):
from tkinter import messagebox
path = self.path.get()
hashType = self.comboBox1.get()
with open(path,'rb') as file:
file_contents = file.read()
if hashType.strip() == "":
messagebox.showinfo("Error", "Nothing to do")
elif hashType.strip() == "Md5":
passwordHash = hashlib.md5(file_contents).hexdigest()
self.result1.place(x=30, y=180)
self.resultVar .set(passwordHash)
self.result_box1.place(x=30, y=220)
elif hashType.strip() == "Sha2":
passwordHash = hashlib.sha256(file_contents).hexdigest()
self.result1.place(x=30, y=180)
self.resultVar.set(passwordHash)
self.result_box1.place(x=30, y=220)
elif hashType.strip() == "Sha1":
passwordHash = hashlib.sha1(file_contents).hexdigest()
self.result1.place(x=30, y=180)
self.resultVar.set(passwordHash)
self.result_box1.place(x=30, y=220)
if __name__ == '__main__':
HashGenerator()