A day ago I started a c# project where I bruteforce passwords. Passwords can be both integers and strings. In the code I check how many characters the password has. Whilst this is kinda cheating it would take too long to crack otherwise. I am posting it here to see if it's good enough.
using System;
namespace Hacking_Project
{
class Program
{
static void Main()
{
//Console Color
Console.ForegroundColor = ConsoleColor.White;
Console.Clear();
//If password is found
bool done = false;
//If the password is a string, not the best name but ok
bool yes = false;
//If the Guessed password is the same number of characters as the original password
int pass = 0;
//Guessed password
string pass_check = "";
//Possible characters for the password
char[] pos = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'};
Console.WriteLine("What is the password?");
//Asking for the password to crack
string password = Console.ReadLine();
//How much characters does the password has. I know that this is kinda cheating, but then the bruteforce would take to much
int digits = password.Length;
//Initialising the random number generator
Random rand = new Random();
//The choices that the calculator will take for the guessed password(int)
int[] choices = new int[digits];
//The choices that the calculator will take for the guessed password(string)
char[] choices1 = new char[digits];
//If the password is a string
for (int i = 0; i < pos.Length; i++)
{
if (password.Contains(pos[i]))
{
password = password.ToLower();
yes = true;
}
}
//The Cracking Part
while (done == false)
{
if (!yes)
{
for (int i = 0; i < digits; i++)
{
choices[i] = rand.Next(0, 9);
pass_check += choices[i];
pass++;
//Console Color
Console.ForegroundColor = ConsoleColor.DarkYellow;
if (pass != digits)
{
Console.Write(choices[i]);
}
else
{
Console.Write(choices[i] + ", ");
}
}
}
else
{
for (int i = 0; i < digits; i++)
{
choices1[i] = pos[rand.Next(pos.Length)];
pass_check += choices1[i];
pass++;
Console.ForegroundColor = ConsoleColor.DarkYellow;
if (pass != digits)
{
Console.Write(choices1[i]);
}
else
{
Console.Write(choices1[i] + ", ");
}
}
}
pass = 0;
if (pass_check == password)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\n\nThe password is: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(pass_check);
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\n\nThe original password is: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(password);
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\n\nDo you want to restart?");
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" => ");
string restart = Console.ReadLine();
restart = restart.ToLower();
if (restart == "yes")
{
Main();
}
else if (restart == "no")
{
done = true;
}
}
//If the password is not found, quessed password is set to empty
else
{
pass_check = "";
}
}
}
}
}
//Initialising the random number generator) Don't explain what you are doing, explain why you are doing it. I didn't look at the code too much, but my first thought with seeingRandomis that you're randomly generating the characters you're generating which can lead to both duplicate and missed guesses, which would add additional time to your algorithm. \$\endgroup\$