Exemplo n.º 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()));
     }
 }
Exemplo n.º 2
0
 private Result <IEnumerable <string> > GetWordsFromSource(IWordSource source)
 {
     return(Text.GetWords()
            .Then(words => words
                  .Select(w => w.ToLowerInvariant())
                  .Select(w => Regex.Replace(w, @"(\W|\d)", string.Empty, RegexOptions.Compiled))
                  .Where(w => !stopWords.GetWords().GetValueOrThrow().Contains(w))));
 }
Exemplo n.º 3
0
 public TextAnalyzer(IWordSource text, IWordSource stopWords,
                     IWordSource partsOfSpeech = null, bool useStems = false)
 {
     this.stopWords     = stopWords;
     this.partsOfSpeech = partsOfSpeech;
     this.useStems      = useStems;
     Text = text;
 }
Exemplo n.º 4
0
        public MaskWordFilter(IWordSource wordSource, char splitChar = '|')
        {
            var banWords = wordSource.GetWordsArray();

            foreach (var s in banWords)
            {
                AddWordToHashtable(s);
            }
        }
 public CloudProcessor(Options options, IWordSource wordSource, IGrammarInfoParser grammarInfoParser,
     GrammarFormJoiner grammarFormJoiner, IWordFilter[] wordFilters,
     IFontManager fontManager, ICloudGenerator cloudGenerator, IColorManager colorManager,
     ICloudRenderer cloudRenderer)
 {
     this.wordSource = wordSource;
     this.grammarInfoParser = grammarInfoParser;
     this.grammarFormJoiner = grammarFormJoiner;
     this.wordFilters = wordFilters;
     wordCount = options.Count;
     this.fontManager = fontManager;
     this.cloudGenerator = cloudGenerator;
     this.colorManager = colorManager;
     this.cloudRenderer = cloudRenderer;
 }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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");
            }
        }
Exemplo n.º 8
0
 public WordSourceService()
 {
     wordsource = new FileWordSource(pathToFile);
 }
Exemplo n.º 9
0
        private void RunWith(IWordSource wordSource)
        {
            var results = m_Analyzer.Analyze(wordSource.Read());

            Console.WriteLine("{0}: {1}", wordSource, results);
        }