Advertisement
Drotika

Untitled

Mar 9th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. from Tkinter import *
  2. import itertools
  3. import os
  4. import binascii
  5. import mnemonic
  6. import random
  7.  
  8.  
  9. class App:
  10. def __init__(self, master):
  11. frame = Frame(master)
  12. frame.pack()
  13. self.inputa_label = Label(frame, text="Input a list of bip39 words with spaces between them:")
  14. self.inputa_label.pack()
  15. self.entry_seed = Entry(frame, bd=3, width=80)
  16. self.entry_seed.pack()
  17. self.button_shuffle = Button(frame, text="Shuffle words", command=self.mix_words)
  18. self.button_shuffle.pack()
  19. self.result_description = Label(frame, text="In this order, your words are a valid bip39 seed:")
  20. self.result_description.pack()
  21. self.result_label = Label(frame, text="")
  22. self.result_label.pack()
  23. self.slogan = Button(frame,
  24. text="Force valid bip39 order",
  25. command=self.main_validate)
  26. self.slogan.pack()
  27. self.button_quit = Button(frame,
  28. text="QUIT", fg="red",
  29. command=frame.quit)
  30.  
  31. self.button_quit.pack()
  32.  
  33. def main_validate(self):
  34. """Checks for a valid bip39 seed from the given list of words."""
  35. self.result_label['text'] = ''
  36. seed_input = []
  37. seed_input = self.entry_seed.get().split()
  38. m = mnemonic.Mnemonic('english')
  39. for subset in itertools.permutations(seed_input, len(seed_input)):
  40. if len(subset) == len(seed_input):
  41. if m.check(' '.join(subset)):
  42. if subset != seed_input:
  43. self.result_label['text'] = ' '.join(subset)
  44. else:
  45. self.result_label['text'] = "There was a problem with the words you gave, maybe they are not on the bip39 word list or the number of words does not work."
  46. break # found a valid one, stop looking.
  47.  
  48. def mix_words(self):
  49. """Shuffles the words in the entry field."""
  50. seed_input = []
  51. seed_input = self.entry_seed.get().split()
  52. # print(seed_input)
  53. shuffled = random.sample(seed_input, len(seed_input))
  54. # print(shuffled)
  55. self.entry_seed.delete(0, END)
  56. self.entry_seed.insert(0, " ".join(shuffled))
  57.  
  58.  
  59. root = Tk()
  60. root.title("Force39")
  61. app = App(root)
  62. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement