Example #1
0
 public static void GetWords(int num, string[] words, IWordSource wordsource, IRandomnessSource randomness)
 {
     for (int i = 0; i < num; i++)
     {
         words[i] = wordsource.GetWord(randomness.NextRandom(0, wordsource.NumWords()));
     }
 }
Example #2
0
        // wordsource should always be the one used to generate the words.
        public static BigInteger CrackingCombinations(string[] words, IWordSource source, PriorKnowledge prior)
        {
            int numChars            = 0;
            int combinationsPerChar = 0;

            if (prior == PriorKnowledge.Passphrase)
            {
                numChars            = words.Length;
                combinationsPerChar = source.NumWords();
            }
            else
            {
                numChars            = String.Join("", words).Length;
                combinationsPerChar = AlphanumSource.Instance.NumWords();
            }
            var perChar = new BigInteger("" + combinationsPerChar);

            return(perChar.Pow(numChars));
        }
Example #3
0
        private void Regenerate()
        {
            if (CanCreatePhrase)
            {
                int num = NumWords;
                Words = new string[num];
                var randomness = RandomnessSourceList.SelectedItem as IRandomnessSource;
                Wordsource = WordsSourceList.SelectedItem as IWordSource;

                int    wordsourceNumWords = Wordsource.NumWords();
                double perWord            = Math.Log(wordsourceNumWords, 2);
                double bits = Words.Length * perWord;

                Utils.GetWords(num, Words, Wordsource, randomness);
                PassphraseOutput = String.Join(" ", Words);

                DoCrackingCalculations();

                NumBitsOutput  = String.Format("{0:0.##} bits", bits);
                NumBitsTooltip = Utils.BitText(perWord, num, bits, wordsourceNumWords);

                perWord = Math.Log(_alphanumSource.NumWords(), 2);
                int alphWords = 0; //(int) Math.Ceiling((float)bits / perWord);
                while (alphWords * perWord < bits)
                {
                    alphWords++;
                }
                var alphanumWords = new string[alphWords];
                bits = alphWords * perWord;
                Utils.GetWords(alphWords, alphanumWords, _alphanumSource, randomness);
                AlphanumOutput   = String.Join("", alphanumWords);
                AlphanumBitsText = Utils.BitText(perWord, alphWords, bits, _alphanumSource.NumWords());

                NotifyPropertyChanged("PassphraseOutput");
                NotifyPropertyChanged("PassphraseBitsText");
                NotifyPropertyChanged("AlphanumOutput");
                NotifyPropertyChanged("AlphanumBitsText");
                NotifyPropertyChanged("NumBitsOutput");
                NotifyPropertyChanged("NumBitsTooltip");
            }
        }