Skip to content

Commit

Permalink
Rejigged the trezor sample mnemonic tools into a little Tkinter gui f…
Browse files Browse the repository at this point in the history
…or taking bip39 seed words and reordering them so they're valid.

Removed tests, readme, setup for now.
  • Loading branch information
IntegersOfK committed Jul 21, 2016
1 parent f9f7720 commit 6aaa6f4
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 2,613 deletions.
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions AUTHORS

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

24 changes: 0 additions & 24 deletions README.rst

This file was deleted.

File renamed without changes.
62 changes: 62 additions & 0 deletions force39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from Tkinter import *
import itertools
import os
import binascii
import mnemonic
import random


class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.inputa_label = Label(frame, text="Input a list of bip39 words with spaces between them:")
self.inputa_label.pack()
self.entry_seed = Entry(frame, bd=3, width=80)
self.entry_seed.pack()
self.button_shuffle = Button(frame, text="Shuffle words", command=self.mix_words)
self.button_shuffle.pack()
self.result_description = Label(frame, text="In this order, your words are a valid bip39 seed:")
self.result_description.pack()
self.result_label = Label(frame, text="")
self.result_label.pack()
self.slogan = Button(frame,
text="Force valid bip39 order",
command=self.main_validate)
self.slogan.pack()
self.button_quit = Button(frame,
text="QUIT", fg="red",
command=frame.quit)

self.button_quit.pack()

def main_validate(self):
"""Checks for a valid bip39 seed from the given list of words."""
self.result_label['text'] = ''
seed_input = []
seed_input = self.entry_seed.get().split()
m = mnemonic.Mnemonic('english')
for subset in itertools.permutations(seed_input, len(seed_input)):
if len(subset) == len(seed_input):
if m.check(' '.join(subset)):
if subset != seed_input:
self.result_label['text'] = ' '.join(subset)
else:
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."
break # found a valid one, stop looking.

def mix_words(self):
"""Shuffles the words in the entry field."""
seed_input = []
seed_input = self.entry_seed.get().split()
# print(seed_input)
shuffled = random.sample(seed_input, len(seed_input))
# print(shuffled)
self.entry_seed.delete(0, END)
self.entry_seed.insert(0, " ".join(shuffled))


root = Tk()
root.title("Force39")
app = App(root)
root.mainloop()
51 changes: 0 additions & 51 deletions generate_vectors.py

This file was deleted.

18 changes: 1 addition & 17 deletions mnemonic/mnemonic.py → mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ def normalize_string(cls, txt):

return unicodedata.normalize('NFKD', utxt)

@classmethod
def detect_language(cls, code):
first = code.split(' ')[0]
languages = cls.list_languages()

for lang in languages:
mnemo = cls(lang)
if first in mnemo.wordlist:
return lang

raise ConfigurationError("Language not detected")

def generate(self, strength=128):
if strength % 32 > 0:
Expand Down Expand Up @@ -134,15 +123,10 @@ def to_mnemonic(self, data):
for i in range(len(b) // 11):
idx = int(b[i * 11:(i + 1) * 11], 2)
result.append(self.wordlist[idx])
if self.detect_language(' '.join(result)) == 'japanese': # Japanese must be joined by ideographic space.
result_phrase = u'\xe3\x80\x80'.join(result)
else:
result_phrase = ' '.join(result)
result_phrase = ' '.join(result)
return result_phrase

def check(self, mnemonic):
if self.detect_language(mnemonic.replace(u'\xe3\x80\x80', ' ')) == 'japanese':
mnemonic = mnemonic.replace(u'\xe3\x80\x80', ' ') # Japanese will likely input with ideographic space.
mnemonic = mnemonic.split(' ')
if len(mnemonic) % 3 > 0:
return False
Expand Down
Loading

0 comments on commit 6aaa6f4

Please sign in to comment.