Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            List <string>       dictionary       = null;
            StopwatchController stopwatch        = new StopwatchController(new System.Diagnostics.Stopwatch());
            DitionaryCreator    ditionaryCreator = new DitionaryCreator();

            if (args.Any(a => a == "help"))
            {
                PrintManual();
                return;
            }
            if (args.Any(a => a == "-bd"))
            {
                PrintPDfForce();
                dictionary = GenerateBirthdayDictionary(stopwatch, ditionaryCreator);
            }
            if (args.Any(a => a == "-kw"))
            {
                PrintPDfForce();
                dictionary = GenerateKeywordsDictionary(stopwatch, ditionaryCreator);
            }
            if (args.Any(a => a == "-df"))
            {
                PrintPDfForce();
                dictionary = LoadDictionary();
            }
            FindPassword(args, dictionary, stopwatch);
        }
Ejemplo n.º 2
0
        private static List <string> GenerateBirthdayDictionary(StopwatchController stopwatch, DitionaryCreator ditionaryCreator)
        {
            List <string> dictionary;
            DateTime      startDate  = new DateTime(1960, 1, 1);
            DateTime      finishDate = DateTime.Now.AddYears(-10);

            Console.WriteLine($"Generate dictionary between {startDate.ToString("dd/MM/yyyy")} and {finishDate.ToString("dd/MM/yyyy")}");
            stopwatch.Start();
            dictionary = ditionaryCreator.GenerateForBirthday(startDate, finishDate);
            stopwatch.Stop();
            Console.WriteLine($"Working time: {stopwatch.Time}\tDictionary length: {dictionary.Count}");
            return(dictionary);
        }
Ejemplo n.º 3
0
        private static void FindPassword(string[] args, List <string> dictionary, StopwatchController stopwatch)
        {
            if (dictionary is null || dictionary.Count < 1)
            {
                return;
            }
            Console.WriteLine("Write path of PDF File:");
            string pdfPath = Console.ReadLine();

            if (!File.Exists(pdfPath))
            {
                Console.WriteLine("404! 404! abort!");
                return;
            }
            if (!IsPasswordProtected(pdfPath))
            {
                Console.WriteLine("Doesn't appear to be password protected...");
                return;
            }
            stopwatch.Start();
            if (args.Any(a => a == "-p"))
            {
                Parallel.ForEach(dictionary, (str, pls) =>
                {
                    if (IsPasswordValid(pdfPath, GetBytes(str)))
                    {
                        Console.WriteLine("Correct password is: {0}", str);
                        stopwatch.Stop();
                        Console.WriteLine($"Working time: {stopwatch.Time}");
                        pls.Break();
                    }
                });
                return;
            }
            else
            {
                foreach (var password in dictionary)
                {
                    if (IsPasswordValid(pdfPath, GetBytes(password)))
                    {
                        Console.WriteLine("Correct password is: {0}", password);
                        stopwatch.Stop();
                        Console.WriteLine($"Working time: {stopwatch.Time}");
                        return;
                    }
                }
            }
            stopwatch.Stop();
            Console.WriteLine($"Password not find. Working time: {stopwatch.Time}");
        }
Ejemplo n.º 4
0
        private static List <string> GenerateKeywordsDictionary(StopwatchController stopwatch, DitionaryCreator ditionaryCreator)
        {
            List <string> dictionary = new List <string>();
            string        str        = "";
            List <string> keywords   = new List <string>();

            while (true)
            {
                Console.WriteLine("Write keyword or stop for exit:");
                str = Console.ReadLine();
                if (str == "stop")
                {
                    break;
                }
                if (!string.IsNullOrEmpty(str))
                {
                    keywords.Add(str);
                }
            }
            stopwatch.Start();
            try
            {
                keywords   = ditionaryCreator.FirstCharUp(keywords);
                dictionary = ditionaryCreator.GenerateForKeywords(keywords, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                stopwatch.Stop();
                Console.WriteLine($"Working time: {stopwatch.Time}\tKeywords: {keywords?.Count}\tDictionary length: {dictionary?.Count}");
            }
            return(dictionary);
        }