-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha1it.py
executable file
·81 lines (63 loc) · 2.01 KB
/
sha1it.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
#!/usr/bin/env python
"""
A GUI Utility for taking the SHA1 hash of a string.
Enter a string. The hash will be shown and copied to the clipboard.
Press Enter to clear the entry. The clipboard will not be cleared.
"""
import hashlib
import Tkinter
import tkFont
class Sha1it(Tkinter.Frame, object):
"""Application main frame.
(As in the primary frame, not like a supercomputer or anything.)
"""
def __init__(self, parent):
super(Sha1it, self).__init__(parent)
self.parent = parent
self.parent.title("Sha1it")
self.font_mono = tkFont.Font(family="Monospace", size=9)
self.entry_var = Tkinter.StringVar()
self.entry_var.trace("w", lambda *args: self.on_change_entry())
self.entry = Tkinter.Entry(self,
width=40,
textvariable=self.entry_var,
font=self.font_mono)
self.entry.grid(sticky=Tkinter.W)
self.entry.focus_set()
self.entry.bind("<Return>", lambda *args: self.on_press_enter())
self.label_hash = Tkinter.Label(self,
text="ab3246947813fd6df239c589f9c8a4d3d5826496",
font=self.font_mono)
self.label_hash.grid(sticky=Tkinter.W)
self.label_clipboard = Tkinter.Label(self,
text="Enter text to get the sha1.",
font=self.font_mono)
self.label_clipboard.grid(sticky=Tkinter.W)
self.grid()
def on_change_entry(self):
plain = self.entry_var.get()
if len(plain) == 0:
return
hashed = hash_sha1(plain)
self.label_hash.config(text=hashed)
copy_to_clipboard(hashed)
self.label_clipboard.config(text=(
"Copied to clipboard. "
"Enter to clear."))
def on_press_enter(self):
self.entry_var.set("")
def hash_sha1(input):
"""Take the sha1 hash of a thing."""
return hashlib.sha1(input).hexdigest()
def copy_to_clipboard(string):
"""Copy a string the system clipboard."""
tk = Tkinter.Tk()
tk.withdraw()
tk.clipboard_clear()
tk.clipboard_append(string)
tk.destroy()
if __name__ == "__main__":
print "Started."
root = Tkinter.Tk()
Sha1it(root)
root.mainloop()