-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (24 loc) · 749 Bytes
/
main.py
File metadata and controls
32 lines (24 loc) · 749 Bytes
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
import hashlib
from browser import alert, document, html
hashes = {
"sha-1": hashlib.sha1,
"sha-256": hashlib.sha256,
"sha-512": hashlib.sha512,
}
def compute_hash(evt):
value = document["text-src"].value
if not value:
alert("You need to enter a value")
return
algo_dropdown = document["algo"]
algo = algo_dropdown.options[algo_dropdown.selectedIndex].value
hash_object = hashes[algo]()
hash_object.update(value.encode())
hex_value = hash_object.hexdigest()
display_hash(hex_value)
def display_hash(hex_value):
text = html.P(hex_value)
hash_display = document["hash-display"]
hash_display.clear()
hash_display <= text
document["submit"].bind("click", compute_hash)