Example #1
0
        /// <summary>
        /// Takes in the words of a mnemonic sentence and it rebuilds the word index, having the valid index allows us to hot swap between languages/word lists :)
        /// </summary>
        /// <param name="wordsInMnemonicSentence"> a string array containing each word in the mnemonic sentence</param>
        /// <returns>The word index that can be used to build the mnemonic sentence</returns>
        private List <int> RebuildWordIndexes(string[] wordsInMnemonicSentence)
        {
            List <int> wordIndexList = new List <int>();
            string     langName      = "English";

            Wordlists.Wordlist wordlist = new Wordlists.English();

            foreach (string s in wordsInMnemonicSentence)
            {
                int idx = -1;

                if (!wordlist.WordExists(s, out idx))
                {
                    throw new Exception("Word " + s + " is not in the wordlist for language " + langName + " cannot continue to rebuild entropy from wordlist");
                }

                wordIndexList.Add(idx);
            }

            return(wordIndexList);
        }
Example #2
0
        /// <summary>
        /// Uses the Wordlist Index to create a scentence ow words provided by the wordlist of this objects language attribute
        /// </summary>
        /// <returns>A scentence of words</returns>
        private string GetMnemonicSentence()
        {
            //trap for words that were not in the word list when built. If custom words were used, we will not support the rebuild as we don't have the words
            if (_wordIndexList.Contains(-1))
            {
                throw new Exception("the wordlist index contains -1 which means words were used in the mnemonic sentence that cannot be found in the wordlist and the index to sentence feature cannot be used. Perhaps a different language wordlist is needed?");
            }

            string mSentence = cEmptyString;

            Wordlists.Wordlist wordlist = new Wordlists.English();

            for (int i = 0; i < _wordIndexList.Count; i++)
            {
                mSentence += wordlist.GetWordAtIndex(_wordIndexList[i]);
                if (i + 1 < _wordIndexList.Count)
                {
                    mSentence += " ";
                }
            }

            return(mSentence);
        }