-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyselmouth.py
69 lines (62 loc) · 2.48 KB
/
pyselmouth.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
from appJar import gui
from PIL import Image, ImageTk
from pyseltongue import PlaintextToHexSecretSharer
import jdice2
def shard():
# 192 seems to be the hard limit on number of characters for now.
# Suggested larger primes list to pyseltongue
text = app.getTextArea("t1")
if len(text) == 0:
app.infoBox("Info","Write your secret in the textbox.")
return
if text[0:2] == "e-":
app.warningBox("Error","This is already sharded.")
return
app.clearTextArea("t1")
total_shares = app.integerBox("Total Shares", "Total Number of Shares to create:", parent=None)
needed_shares = app.integerBox("Needed Shares", "Number of Shares to recreate the secret:", parent=None)
try:
shares = PlaintextToHexSecretSharer.split_secret(text, needed_shares, total_shares)
s = ""
for share in shares:
s += share + "\n" + "\n"
app.setTextArea("t1",s)
except Exception as e:
error = str(e)
app.warningBox("Error",error)
def reform():
text = app.getTextArea("t1")
if len(text) == 0:
app.infoBox("Info","Paste your shards/shares into the textbox.")
return
shards = text.split("\n")
cleanshards = [x for x in shards if x] #list comprehension ftw
try:
recovered = PlaintextToHexSecretSharer.recover_secret(cleanshards)
except Exception as e:
error = str(e)
app.warningBox("Error",error)
return
app.clearTextArea("t1")
app.setTextArea("t1",recovered)
def dice():
app.clearTextArea("t1")
yn = app.yesNoBox("BIP39","Create a 24-word BIP39-compliant seed phrase?")
if yn:
phrase = jdice2.getbip39()
if not yn:
n = app.integerBox("Words", "How many words?:", parent=None)
phrase = jdice2.getwords(n)
app.setTextArea("t1",phrase)
def clear():
app.clearTextArea("t1")
################################################################################################################
# GUI STARTS HERE
################################################################################################################
with gui("pyselmouth", "700x700", bg='#5d5d5d', font={'family':'Parseltongue','size':40}) as app:
app.label("pyselmouth", bg='#1a472a', fg='white')
photo = ImageTk.PhotoImage(Image.open("assets/snake.png"))
app.addImageData("pic", photo, fmt="PhotoImage")
app.setPadding(15,15)
app.addTextArea("t1")
app.buttons(["Shard", "Reveal","Clear","Dice"], [shard, reform, clear,dice])