forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (36 loc) · 899 Bytes
/
Copy pathmain.py
File metadata and controls
45 lines (36 loc) · 899 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
33
34
35
36
37
38
39
40
41
42
43
44
45
from browser import alert, window
from javascript import this
import hashlib
hashes = {
"sha-1": hashlib.sha1,
"sha-256": hashlib.sha256,
"sha-512": hashlib.sha512,
}
Vue = window.Vue
def compute_hash(evt):
value = this().input_text
if not value:
alert("You need to enter a value")
return
hash_object = hashes[this().algo]()
hash_object.update(value.encode())
hex_value = hash_object.hexdigest()
this().hash_value = hex_value
def created():
for name in hashes:
this().algos.append(name)
this().algo = next(iter(hashes))
app = Vue.createApp(
{
"el": "#app",
"created": created,
"data": lambda _: {
"hash_value": "",
"algos": [],
"algo": "",
"input_text": "",
},
"methods": {"compute_hash": compute_hash},
}
)
app.mount("#app")