public override double entropy(PasswordSequenceConfiguration config)
        {
            double entropyVal = 0;

            if (Length > 0)
            {
                uint len          = Length;
                uint charlist_len = 0;
                if (Characters != null)
                {
                    charlist_len = (uint)Characters.Count;
                }
                if (Characters == null || !Characters.Override)
                {
                    charlist_len += (uint)config.DefaultCharacters.Count;
                }

                if (!AllowDuplicate)
                {
                    len = (len <= charlist_len ? len : charlist_len);
                }

                double cur_len_entropy = 0.0;
                uint   cur_len         = len;
                while (cur_len > 0 && charlist_len > 0)
                {
                    cur_len_entropy += Math.Log(charlist_len, 2);

                    if (LengthStrength < StrengthEnum.Full)
                    {
                        if (cur_len > 1)
                        {
                            entropyVal += (1 - (double)LengthStrength / 100) * cur_len_entropy / len;
                        }
                    }

                    if (!AllowDuplicate)
                    {
                        charlist_len -= 1;
                    }
                    cur_len -= 1;
                }
                entropyVal += ((double)LengthStrength / 100) * cur_len_entropy;
            }

            return(entropyVal);
        }
Esempio n. 2
0
        public override double entropy(PasswordSequenceConfiguration config)
        {
            double entropyVal = 0;


            List <string> wordList = new List <string>();

            if (Words != null)
            {
                wordList.AddRange(Words);
            }
            if (Words == null || !Words.Override)
            {
                wordList.AddRange(config.DefaultWords);
            }

            List <BaseSubstitution> applicableSubstitution = new List <BaseSubstitution>();

            if (Substitution > PercentEnum.Never)
            {
                if (Substitutions != null)
                {
                    applicableSubstitution.AddRange(Substitutions);
                }
                if (Substitutions == null || !Substitutions.Override)
                {
                    applicableSubstitution.AddRange(config.DefaultSubstitutions);
                }
            }

            if (wordList.Count > 0)
            {
                entropyVal += Math.Log(wordList.Count, 2);
            }

            /* collect stats about the word list and how substitions apply */
            double avg_word_len    = 0;
            int    subst_hit_count = 0;

            foreach (string word in wordList)
            {
                avg_word_len += word.Length;
                foreach (BaseSubstitution substitution in applicableSubstitution)
                {
                    subst_hit_count += new SubstitutionVisitor(null)
                                       .CountSubstitution(substitution, word);
                }
            }
            avg_word_len /= wordList.Count;
            double avg_subst_hits = (double)subst_hit_count / wordList.Count;

            /* apply information added by capitalization */
            double cap_chance = 0;

            if (Capitalize != CapitalizeEnum.Proper)
            {
                cap_chance = (double)Capitalize / 100.0;
            }
            if (cap_chance > 0.0 && cap_chance < 1.0)
            {
                entropyVal += avg_word_len * cap_chance * Math.Log(1 / cap_chance, 2);
                entropyVal += avg_word_len * (1 - cap_chance) * Math.Log(1 / (1 - cap_chance), 2);
            }

            /* apply average information added by substitutions */
            double subst_chance = (double)Substitution / 100.0;

            subst_chance = (double)Substitution / 100.0;
            if (subst_chance > 0.0 && subst_chance < 1.0)
            {
                entropyVal += avg_subst_hits * subst_chance * Math.Log(1 / subst_chance, 2);
                entropyVal += avg_subst_hits * (1 - subst_chance) * Math.Log(1 / (1 - subst_chance), 2);
            }

            /* Chance of not including the word actually decreases entropy
             * because there is a chance the attacker needs to try fewer words.
             */
            entropyVal = entropyVal * (double)Probability / 100;

            return(entropyVal);
        }
Esempio n. 3
0
 public abstract double entropy(PasswordSequenceConfiguration config);