Exemplo n.º 1
0
        static void GeneratePasswords()
        {
            var enumerables = new List <IEnumerator <string> >();
            int threadMax   = Process.GetCurrentProcess().Threads.Count;
            var lengths     = new[] { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            var split       = (int)Math.Ceiling(lengths.Length / (threadMax * 1.0));

            foreach (var l in lengths)
            {
                enumerables.Add(HMMGroup.Load(string.Format("TrainedModels/hmm_length_of_{0}.data", l)).Generate(l).GetEnumerator());
            }

            Parallel.For(0, threadMax, x =>
            {
                int start   = x * split;
                int end     = Math.Min(start + split, lengths.Length);
                var items   = enumerables.Skip(start).Take(split).ToList();
                int running = items.Count;
                do
                {
                    items.ForEach(i =>
                    {
                        var current = i.Current;
                        Console.WriteLine(current);
                        i.MoveNext();
                        if (current == i.Current)
                        {
                            running--;
                        }
                    });
                } while (running > 0);
            });
        }
Exemplo n.º 2
0
        static void GeneratePasswords(string path, int?length = null)
        {
            //foreach (var pwd in HMMGroup.Load(path).Generate(length))
            //{
            //    Console.WriteLine(pwd);
            //}

            var enumerables = new List <IEnumerator <string> >();
            int threadMax   = Process.GetCurrentProcess().Threads.Count;
            var lengths     = length == null ? new[] { 1, 2, 3, 4, 5 } : new[] { length.Value };
            var split       = (int)Math.Ceiling(lengths.Length / (threadMax * 1.0));

            foreach (var l in lengths)
            {
                enumerables.Add(HMMGroup.Load(path).Generate(l).GetEnumerator());
            }

            Parallel.For(0, threadMax, x =>
            {
                int start   = x * split;
                int end     = Math.Min(start + split, lengths.Length);
                var items   = enumerables.Skip(start).Take(split).ToList();
                int running = items.Count;
                do
                {
                    items.ForEach(i =>
                    {
                        var current = i.Current;
                        Console.WriteLine(current);
                        i.MoveNext();
                        if (current == i.Current)
                        {
                            running--;
                        }
                    });
                } while (running > 0);
            });
        }