gpt4 book ai didi

C# bruteforce md5 哈希字符串

转载 作者:行者123 更新时间:2023-11-30 17:45:11 25 4
gpt4 key购买 nike

我正在尝试创建一个 C# 应用程序,它使用暴力破解来恢复 MD5 散列密码(仅用于测试,限于小写字母 a-z)

我在使用循环时遇到了问题。它需要在尝试 a-z 之后添加一个新字符,并开始一个新的循环来尝试所有可能的组合。

下面的代码可以工作,但远非最佳。关于如何制作“智能”循环的任何提示?

public void CompareMD5()
{
string outputMD5 = "";
int chars = 1;
int loop = 0;
int i = 0;
int ii = 0;
while (!outputMD5.Equals(targetMD5))
{
if (chars == 1)
{
Console.WriteLine("trying " + charSet[i]);
outputMD5 = GenerateMD5(charSet[i]);
i++;
if (i >= charSet.Length)
{
Console.WriteLine("\n" + "*** ADDING CHAR ***" + "\n");
i = 0;
chars++;
}
}

if (chars == 2)
{
Console.WriteLine("trying " + charSet[i] + charSet[ii]);
outputMD5 = GenerateMD5(charSet[i] + charSet[ii]);
i++;
if (i >= charSet.Length)
{
i = 0;
ii++;
}
if (ii >= charSet.Length)
{
ii = 0;
i++;
loop++;
}
if (loop == 1)
{
Console.WriteLine("\n" + "*** ADDING CHAR ***" + "\n");
i = 0;
ii = 0;
chars++;
}
}
}
}

最佳答案

试试这个:

  // 'a', ..., 'z', 'aa', ..., 'zz', 'aaa', ..., 'zzz'
int maxLength = 3;

for (int length = 1; length <= maxLength; ++length) {
// initial combination "a...a" ('a' length times)
StringBuilder Sb = new StringBuilder(new String('a', length));

while (true) {
String value = Sb.ToString();
//TODO: Test MD5 here
// if (value.Equals(targetMD5)) {...}

// Is this the last combination? (all 'z' string)
if (value.All(item => item == 'z'))
break;

// Add one: aaa -> aab -> ... aaz -> aba -> ... -> zzz
for (int i = length - 1; i >= 0; --i)
if (Sb[i] != 'z') {
Sb[i] = (Char) (Sb[i] + 1);

break;
}
else
Sb[i] = 'a';
}
}

关于C# bruteforce md5 哈希字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28210579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com