Hack Forums
[C#] [C#] The real Brute Force by Mathian - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] [C#] The real Brute Force by Mathian (/showthread.php?tid=5922901)



[C#] The real Brute Force by Mathian - Mathian - Dec 26, 2018

Hi! When I first heard about BruteForce, I imagined going over all the options from "a" to "z". I have created such code long ago, but it would be worth thinking about exceptions:
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace Cycle
{
    class Program
    {
        static void Main(string[] args)
        {
            string Chars = "Alphabet";
            for (int i = 0; i <= 3; i++)
            {
                foreach (var Password in GetCombinations(Chars.ToArray(), i))
                    Console.WriteLine(Password);
            }
            Console.ReadLine();
        }
        private static IEnumerable<string> GetCombinations(char[] Chars, int MaximumLength)
        {
            if (MaximumLength < 1) yield break;
            foreach (var a in Chars)
            {
                yield return a.ToString();
                foreach (var b in GetCombinations(Chars, MaximumLength - 1)) yield return a + b;
            }
        }
    }
}
With this code you can get absolutely all combinations of passwords, but it will take an incredible amount of time. I'm not saying that this is the best way (rather the opposite), but this is the real Brute Force.

Spoiler (Click to View)

Author: Mathian Developer


RE: [C#] The real Brute Force by Mathian - HFDone - Dec 26, 2018

better use Parallel.ForEach


RE: [C#] The real Brute Force by Mathian - .TheMarv - Dec 26, 2018

By outputting every password to console, you're massively reducing the speed of the program


RE: [C#] The real Brute Force by Mathian - Mathian - Dec 26, 2018

(Dec 26, 2018 08:48 PM).TheMarv Wrote:  By outputting every password to console, you're massively reducing the speed of the program
Oh my God! Friend, you can not output to the console. I provided the generation algorithm


RE: [C#] The real Brute Force by Mathian - .TheMarv - Dec 27, 2018

Code
foreach (var Password in GetCombinations(Chars.ToArray(), i))
                    Console.WriteLine(Password);

This will output every possibility to the console, that's what I was referring to


RE: [C#] The real Brute Force by Mathian - Paskowsky - Dec 27, 2018

@OP thank you for sharing this!

(Dec 27, 2018 01:31 AM).TheMarv Wrote:  
Code
               foreach (var Password in GetCombinations(Chars.ToArray(), i))
                   Console.WriteLine(Password);

This will output every possibility to the console, that's what I was referring to

He has provided the algorithm to generate passwords, where you want them outputted is your choice 🤝

Regards,
Paskowsky


RE: [C#] The real Brute Force by Mathian - .TheMarv - Dec 27, 2018

(Dec 27, 2018 03:36 AM)Paskowsky Wrote:  @OP thank you for sharing this!


He has provided the algorithm to generate passwords, where you want them outputted is your choice  🤝

Regards,
Paskowsky

Ofc, I just wanted to point out, that putting it out in the console would decrease the performance.


RE: [C#] The real Brute Force by Mathian - Mathian - Dec 27, 2018

(Dec 27, 2018 01:31 AM).TheMarv Wrote:  
Code
               foreach (var Password in GetCombinations(Chars.ToArray(), i))
                   Console.WriteLine(Password);

This will output every possibility to the console, that's what I was referring to
You can save to file, add to database or apply. Conclusion in the console - a demonstration of work


(Dec 27, 2018 03:36 AM)Paskowsky Wrote:  @OP thank you for sharing this!


He has provided the algorithm to generate passwords, where you want them outputted is your choice  🤝

Regards,
Paskowsky
Enjoy :)


RE: [C#] The real Brute Force by Mathian - 0xDEAD10CC - Dec 27, 2018

Enumerators and IEnumerable = very slow. An iterative approach would be much faster. This code snippet is really not useful in the real world for relatively good bruteforcing.


RE: [C#] The real Brute Force by Mathian - Mathian - Dec 28, 2018

(Dec 27, 2018 03:20 PM)0xDEAD10CC Wrote:  Enumerators and IEnumerable = very slow. An iterative approach would be much faster. This code snippet is really not useful in the real world for relatively good bruteforcing.
I by no means suggest to produce brutus by this method