-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
86 lines (74 loc) · 3.44 KB
/
gui.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
from main import HashingFunctions
import tkinter as tk
import random as rand
class Display:
#make a GUI with the following elements
#Top box is an input box that can
# 1. display the mnemonic phrase generated by the user
# 2. have the user input a memonic phrase
#Bottom left will have 2 buttons
# 1. one button to start collecting entropy
# 2. one button to generate mnemonic phrase and key
#Bottom right will have a display showing master key
def __init__(self):
self.h = HashingFunctions()
self.win1 = tk.Tk()
self.win1.wm_title('Mnemonic Phrase Generator')
self.win1.resizable(width=False, height=False)
self.mnemonicLabel = tk.Label(self.win1, text = 'Mnemonic Phrase')
self.mnemonicBox = tk.Text(self.win1, height=5)
self.keyLabel = tk.Label(self.win1, text = 'binary seed')
self.keyBox = tk.Text(self.win1, height=5)
self.numWords = tk.StringVar()
def user_provided_entropy(self):
#user can decide how many words they want in their phrase
#self.numWords = self.wordOptions.get()
size = {'12': 128, '15': '160', '18': '192', '21':'224', '24': '256'}
length = size[self.numWords.get()]
ent = format(rand.randrange(1,2**int(length)), 'x')
#bin_ent = format(ent, f'0{length}b')
self.h.get_input(ent)
self.h.create_check_sum()
self.h.create_word_list()
mnemonic = self.h.result_word_list
self.keyBox.delete('1.0', tk.END)
self.mnemonicBox.delete('1.0', tk.END)
self.mnemonicBox.insert('1.0', mnemonic.rstrip())
mnemonic = self.mnemonicBox.get('1.0', tk.END)
self.h.create_binary_seed()
key = self.h.binary_seed
self.keyBox.insert('1.0', key)
def user_provided_mnemonic(self):
mnemonic = self.mnemonicBox.get('0.0', tk.END)
key = HashingFunctions(None, mnemonic.rstrip())
key.create_binary_seed()
result_key = key.binary_seed
self.keyBox.delete('1.0', tk.END)
self.keyBox.insert('1.0', result_key)
def create_dropdown(self):
optionList = (12, 15, 18, 21, 24)
self.numWords.set(optionList[0])
self.wordOptions = tk.OptionMenu(self.win1, self.numWords, *optionList)
def create_buttons(self):
self.create_dropdown()
self.entropyButton = tk.Button(self.win1, text = 'create mnemonic phrase', command = self.user_provided_entropy) #add command from hash class
self.generateButton = tk.Button(self.win1, text = 'create binary seed', command = self.user_provided_mnemonic) #add create_word_list function
def main_window(self):
self.label = tk.Label(self.win1, text='entropy')
self.entry = tk.Entry(self.win1, bd=5)
def window_elements(self):
self.mnemonicLabel.grid(row=0, column=1, columnspan=3)
self.mnemonicBox.grid(column=1, columnspan=3, row=1, padx=10, pady=10)
self.keyBox.grid(column=1, columnspan=3, row=1, padx=10, pady=10)
self.entropyButton.grid(column=1, row=2)
self.generateButton.grid(column =2, row = 2)
self.wordOptions.grid(column=3, row=2)
self.keyLabel.grid(column=1, columnspan=2, row=3)
self.keyBox.grid(column=1, columnspan=2, row=4)
def display_window(self):
self.create_buttons()
self.main_window()
self.window_elements()
self.win1.mainloop()
if __name__ == '__main__':
Display().display_window()