static void Main()
        {
            Cracking cracker = new Cracking();

            cracker.RunCrakingThreaded();
            Console.ReadKey();
        }
        static void Main()
        {
            Cracking cracker = new Cracking();

            cracker.RunCracking();

            Console.ReadLine();
        }
示例#3
0
        private async Task <List <UserInfoClearText> > DoHack(WorkInfo work)
        {
            Cracking crack = new Cracking();

            List <UserInfoClearText> result = await Task.Run(() => crack.RunCracking(work));

            return(result);
        }
示例#4
0
        static void Main()
        {
            Cracking cracker = new Cracking();
            //cracker.RunCracking();

            Thread myThread  = new Thread(new ThreadStart(cracker.RunCracking()));
            Thread myThread2 = new Thread(new ThreadStart(cracker.RunCracking()));



            //Task.Factory.StartNew(() => cracker.RunCracking());
        }
示例#5
0
        static void Main()
        {
            Cracking cracker = new Cracking();

            Console.WriteLine("---> Centralized:");
            cracker.RunCracking();

            Console.WriteLine();
            Console.WriteLine("---> Simple (one threaded encryption) Pipeline:");
            cracker.RunCrackingModified(1);

            Console.WriteLine();
            Console.WriteLine("---> Master/Slave'd (10-threaded encryption) Pipeline:");
            cracker.RunCrackingModified(10);

            Console.WriteLine();
            Console.WriteLine("Program ended successfully!");
            Console.ReadLine();
        }
示例#6
0
        public void RunCrackingModified(int encryptorCount)
        {
            dictionaryWordCount = 0;

            Stopwatch stopwatch = Stopwatch.StartNew();

            List <UserInfo>          userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt");
            List <UserInfoClearText> result    = new List <UserInfoClearText>();

            BlockingCollection <string> wordDictionary = new BlockingCollection <string>();

            BlockingCollection <string> transformedWordsDictionary = new BlockingCollection <string>(10000);

            //Tuple is used for joining passwords with their encrypted version, so that we will not need to search for them in other threads,
            //e.g.: password (string): "pswd", encrypted password (byte[]): "????????"
            BlockingCollection <Tuple <string, byte[]> > encryptedWordsDictionary = new BlockingCollection <Tuple <string, byte[]> >();

            //Only one cracker is veeeeeeeeeeeeery slow
            //            Parallel.Invoke(() => ReadDictionary(dictionary),
            //                () => TransformDictionary(dictionary, transformedDictionary),
            //                () => EncryptDictionary(transformedDictionary, encryptedDictionary),
            //                () => ComparePasswords(userInfos, encryptedDictionary),
            //                () => PrintCounts(dictionary, transformedDictionary, encryptedDictionary)
            //                );

            //This is a much faster solution - to make much more hash calculators

            //Making many crackers, so that we could start them in separate threads. We can't use one Cracker object,
            //because one method can only be used by one thread at the same time.
            //You can change the number of "crackers" by changing the value of howManyCrackers. It should be at least 1.
            Cracking[] crackingObjects;
            int        howManyCrackers = encryptorCount;

            crackingObjects = new Cracking[howManyCrackers];
            for (int i = 0; i < howManyCrackers; i++)
            {
                crackingObjects[i] = new Cracking();
            }

            //Starting all the tasks except EncryptDictionary
            Task.Run(() => ReadDictionary(wordDictionary));
            Task.Run(() => TransformDictionary(wordDictionary, transformedWordsDictionary));
            //ComparePasswords is going to return a list of found passwords, so we are making it as a Task with return:
            Task <List <UserInfoClearText> > taskOfComparing = Task <List <UserInfoClearText> > .Factory.StartNew(
                () => ComparePasswords(userInfos, encryptedWordsDictionary)
                );

            //Run a thread for seeing how many things there are in BlockingCollections every second, while debugging:
            //Task.Run(() => PrintCounts(wordDictionary, transformedWordsDictionary, encryptedWordsDictionary));

            //The bottleneck is here (most of the calculations are made in method EncryptDictionary), so
            //we are making few processes who encrypt passwords separately.
            //So now we are running all the EncryptDictionary threads in parallel!
            Parallel.For(0, howManyCrackers,
                         (i) => crackingObjects[i].EncryptDictionary(transformedWordsDictionary, encryptedWordsDictionary));
            //Can also use Tasks instead of parallel, and if you want more Encryptors and/or Comparators:
            //            for (int i = 0; i < howManyCrackers/2; i++)
            //            {
            //                int j = i;
            //                Task.Run(() => (new Cracking()).ComparePasswords(userInfos, encryptedDictionary));
            //            }
            //
            //            for (int i = 0; i < howManyCrackers / 2; i++)
            //            {
            //                int j = i;
            //                Task.Run(() => crackingMachinesHaha[j].EncryptDictionary(transformedDictionary, encryptedDictionary));
            //            }

            //Saving results (this will wait here until the ComparePasswords task in object taskOfComparing will finish it's work):
            result = taskOfComparing.Result;

            //Printing results and stopping stopwatch
            stopwatch.Stop();
            Console.WriteLine(string.Join(", ", result));
            Console.WriteLine("Out of {0} password {1} was found ", userInfos.Count, result.Count);
            Console.WriteLine();
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);

            Console.WriteLine("Average speed (words/second): {0}", dictionaryWordCount / (ulong)(stopwatch.Elapsed.Seconds));
        }