Bruteforcing पासवर्ड
Aug 21 2020
एक दिन पहले मैंने एसी # प्रोजेक्ट शुरू किया था, जहाँ मैं पासवर्ड्स को bruteforce करता हूँ। पासवर्ड पूर्णांक और तार दोनों हो सकते हैं। कोड में मैं जांचता हूं कि पासवर्ड में कितने वर्ण हैं। जब तक यह थोड़े धोखा है तब तक अन्यथा दरार करने के लिए बहुत लंबा समय लगेगा। मैं इसे यहाँ पोस्ट कर रहा हूँ देखने के लिए कि क्या यह काफी अच्छा है।
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 = "";
}
}
}
}
}
जवाब
2 MaLiN2223 Aug 23 2020 at 05:20
अस्वीकरण: नीचे सिर्फ मेरी राय है, कृपया इसे सत्य के स्रोत के रूप में न मानें। इसके अलावा, मैं यह मान रहा हूं कि कोड अपेक्षा के अनुरूप काम करता है - मैं प्रदर्शन या वैधता में नहीं रहूंगा।
- बहुत सारी टिप्पणियां, इसके बजाय कोड को अधिक व्याख्यात्मक बनाने का प्रयास करती हैं। चाचा बॉब ने इसे सबसे अच्छा कहा: 'एक टिप्पणी अपने आप को कोड में व्यक्त करने में विफलता है' (जब तक कि यह 'क्यों' नहीं है जिसे निश्चित रूप से समझाया नहीं जा सकता)।
- कोड को छोटे और एकल जिम्मेदारी कार्यों / कक्षाओं में विभाजित करें , मार्गदर्शन के लिए यहां देखें ।
- कंसोल से संबंधित संचालन को एक अलग वर्ग (एक आवरण) में सौंपा जा सकता है, ताकि भविष्य में अन्य स्रोतों से इनपुट / आउटपुट को संभालने के लिए इसे आसानी से बढ़ाया जा सके। इसके अलावा, दोहराव से बचने के लिए (उदाहरण
\n\nके लिए स्ट्रिंग्स के infront लेखन को दूर किया जा सकता है)। - परिवर्तनीय नामों को सामग्री को इंगित करना चाहिए (जब तक कि यह बहुत स्पष्ट न हो)। आपने एक टिप्पणी लिखी है 'सबसे अच्छा नाम नहीं, लेकिन ठीक है', हाँ - यह सबसे अच्छा नाम नहीं है लेकिन मुझे नहीं लगता कि यह 'ठीक' है। कोड के माध्यम से आधा रास्ता मुझे यह जांचने के लिए स्क्रॉल करना पड़ा कि इस चर का क्या मतलब है, यह सही नहीं है। की तरह चर के लिए इसी तरह से चला जाता है
choices1,digits,posऔर अन्य। while (done == false)हो सकता है किwhile(!done)यह 'अंग्रेजी में' छोटी और अधिक व्याख्यात्मक दोनों हो ।- का प्रयोग करें
Console.WriteLineबजाय जोड़ने की\n\n(आप भी कर सकते हैंConsole.WriteLine("")। - के लिए पुनरावृत्ति के बजाय लूप का उपयोग करें
Main। उसके दो कारण हैं: आप स्टैक को पार कर सकते हैं (मनुष्यों के लिए (लेकिन कोई भी बॉट इसे आसानी से कर सकता है)) और दूसरों के द्वारा रिकर्सिव फंक्शन के बजाय गेम लूप देखना अधिक अपेक्षित होगा । - पुनरारंभ के लिए संभावित इनपुट मान प्रदर्शित करें, उपयोगकर्ता कोशिश कर सकता है
Y, जो काम नहीं करेगा।