public IEnumerable <String> Generate(ICommonSettings settings, IPoolsCollector collector)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            if (settings.Length < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Length)} must be greater than zero.");
            }

            List <String> results = new List <String>();

            for (Int32 count = 0; count < settings.Amount; count++)
            {
                List <String> sources = new List <String>();

                switch (settings.Type)
                {
                case CommonType.InternetPassword1:
                    this.ApplySourcesType1(collector, settings.Length, sources);
                    break;

                case CommonType.InternetPassword2:
                    this.ApplySourcesType2(collector, settings.Length, sources);
                    break;

                case CommonType.InternetPassword3:
                    this.ApplySourcesType3(collector, settings.Length, sources);
                    break;

                case CommonType.InternetPasswordX:
                    this.ApplySourcesTypeX(collector, settings.Length, sources);
                    break;

                default:
                    throw new NotSupportedException($"Common type of \"{settings.Type}\" is not supported.");
                }

                String result = sources.Raffle(this.random);

                results.Add(result);
            }

            this.DumpGeneratorResults(settings, results);

            return(results);
        }
示例#2
0
        public IEnumerable<String> Generate(ICommonSettings settings, IPoolsCollector collector)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            if (settings.Length < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Length)} must be greater than zero.");
            }

            if (settings.Amount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Amount)} must be greater than zero.");
            }

            Pools pools = Pools.Nothing;

            if (settings.IsUppers) { pools |= Pools.Uppers; }
            if (settings.IsLowers) { pools |= Pools.Lowers; }
            if (settings.IsDigits) { pools |= Pools.Digits; }
            if (settings.IsExtras) { pools |= Pools.Extras; }

            String source = collector.Collect(pools);

            if (String.IsNullOrWhiteSpace(source))
            {
                return Enumerable.Empty<String>();
            }

            IEnumerable<String> results = null;

            switch (settings.Type)
            {
                case CommonType.PasswordManager1:
                case CommonType.PasswordManager2:
                case CommonType.PasswordManager3:
                    results = this.Generate(source, settings.Length, settings.Amount);
                    break;
                default:
                    throw new NotSupportedException($"Common type of \"{settings.Type}\" is not supported.");
            }

            this.DumpGeneratorResults(settings, results);

            return results;
        }
示例#3
0
        public IEnumerable <String> Generate(ICommonSettings settings, IGeneratorSettings source)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (settings.Amount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Amount)} must be greater than zero.");
            }

            if (settings.Length < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Length)} must be greater than zero.");
            }

            IPoolsCollector collector = CollectorFactory.Create <IPoolsCollector>();

            switch (settings.Type)
            {
            case CommonType.InternetPassword1:
            case CommonType.InternetPassword2:
            case CommonType.InternetPassword3:
            case CommonType.InternetPasswordX:
                return(this.GenerateInternetPasswords(settings, collector));

            case CommonType.PasswordManager1:
            case CommonType.PasswordManager2:
            case CommonType.PasswordManager3:
                return(this.GenerateManagerPasswords(settings, collector));

            case CommonType.WepKey64Bit:
            case CommonType.WepKey128Bit:
            case CommonType.WepKey152Bit:
            case CommonType.WepKey256Bit:
            case CommonType.WepKeyCustom:
            case CommonType.WpaKey:
            case CommonType.Wpa2Key:
                return(this.GenerateWirelessPasswords(settings, collector));

            default:
                throw new NotSupportedException($"Common type of {settings.Type} is not supported.");
            }
        }
        private void ApplySourcesTypeX(IPoolsCollector collector, Int32 length, List <String> sources)
        {
            Int32[] counts = this.CalculateCounts(length);

            for (Int32 index = 0; index < counts[0]; index++)
            {
                if (index == 0)
                {
                    sources.Add(collector.Consonants.Shuffle(this.random).ToUpper());
                }
                else if (index % 2 != 0)
                {
                    sources.Add(collector.Vowels.Shuffle(this.random));
                }
                else
                {
                    sources.Add(collector.Consonants.Shuffle(this.random));
                }
            }

            for (Int32 index = 0; index < counts[1]; index++)
            {
                sources.Add(collector.Collect(Pools.Symbols | Pools.Operators | Pools.Punctuations | Pools.Spaces).Shuffle(this.random));
            }

            for (Int32 index = 0; index < counts[2]; index++)
            {
                if (index == 0)
                {
                    sources.Add(collector.Vowels.Shuffle(this.random).ToUpper());
                }
                else if (index % 2 != 0)
                {
                    sources.Add(collector.Consonants.Shuffle(this.random));
                }
                else
                {
                    sources.Add(collector.Vowels.Shuffle(this.random));
                }
            }

            for (Int32 index = 0; index < counts[3]; index++)
            {
                sources.Add(collector.Digits.Shuffle(this.random));
            }
        }
 private void ApplySourcesType1(IPoolsCollector collector, Int32 length, List <String> sources)
 {
     for (Int32 index = 0; index < length; index++)
     {
         if (index == 0)
         {
             sources.Add(collector.Consonants.Shuffle(this.random).ToUpper());
         }
         else if (index + 2 >= length)
         {
             sources.Add(collector.Digits.Shuffle(this.random));
         }
         else if (index % 2 != 0)
         {
             sources.Add(collector.Vowels.Shuffle(this.random));
         }
         else
         {
             sources.Add(collector.Consonants.Shuffle(this.random));
         }
     }
 }
 public EntropyCalculator(IPoolsCollector collector)
 {
     this.collector = collector ?? throw new ArgumentNullException(nameof(collector));
 }
        private void ApplySourcesType3(IPoolsCollector collector, Int32 length, List <String> sources)
        {
            // TODO: Change algorithm so that it better fits the rules: Cvcv[0..n/2-1]XVcvc[n/-1..n-3]DDD
            // C = consonant; V = Vowel; X = Extra; D = Digit

            Int32 count = 0;
            Int32 index = 0;

            sources.Add(collector.Consonants.Shuffle(this.random).ToUpper());
            index++;

            if (index >= length)
            {
                return;
            }

            count = (length - 3) / 2;

            for (; index < count; index++)
            {
                if (index % 2 != 0)
                {
                    sources.Add(collector.Vowels.Shuffle(this.random));
                }
                else
                {
                    sources.Add(collector.Consonants.Shuffle(this.random));
                }
            }

            if (index >= length)
            {
                return;
            }

            sources.Add(collector.Collect(Pools.Symbols | Pools.Operators | Pools.Punctuations | Pools.Spaces).Shuffle(this.random));
            index++;

            if (index >= length)
            {
                return;
            }

            sources.Add(collector.Vowels.Shuffle(this.random).ToUpper());
            index++;

            if (index >= length)
            {
                return;
            }

            count = length - 3;

            for (; index < count; index++)
            {
                if (index % 2 == 0)
                {
                    sources.Add(collector.Vowels.Shuffle(this.random));
                }
                else
                {
                    sources.Add(collector.Consonants.Shuffle(this.random));
                }
            }

            if (index >= length)
            {
                return;
            }

            count = length;

            for (; index < count; index++)
            {
                sources.Add(collector.Digits.Shuffle(this.random));
            }
        }
示例#8
0
        private IEnumerable <String> GenerateWirelessPasswords(ICommonSettings settings, IPoolsCollector collector)
        {
            IWirelessPasswordGenerator generator = GeneratorFactory.Create <IWirelessPasswordGenerator>();

            return(generator.Generate(settings, collector));
        }
示例#9
0
        private IEnumerable <String> GenerateManagerPasswords(ICommonSettings settings, IPoolsCollector collector)
        {
            IPasswordManagerGenerator generator = GeneratorFactory.Create <IPasswordManagerGenerator>();

            return(generator.Generate(settings, collector));
        }