private void UpdateProgressbar(STProgressBar progressBar, int length, int maxLength) { if (progressBar.InvokeRequired) { progressBar.Invoke((MethodInvoker) delegate { progressBar.Task = $"Searching characters {length} of max {maxLength}"; progressBar.Value = ((length * 100) / maxLength); progressBar.Refresh(); }); } }
private void BruteForceHashes(STProgressBar progressBar, string hashType) { if (bruteForceHashTB.Text.Length == 0) { return; } var characterSet = SetupCharacters(); CancelOperation = false; List <ulong> hashes = new List <ulong>(); foreach (var line in bruteForceHashTB.Lines) { ulong hash = 0; ulong.TryParse(line, out hash); if (hash == 0) { continue; } hashes.Add(hash); } if (hashes.Count == 0) { return; } int maxLength = (int)maxLengthUD.Value; char lastChar = 'z'; var firstChar = characterSet.FirstOrDefault(); int charIndex = 0; bool useSpace = true; for (int length = 1; length <= maxLength; ++length) { UpdateProgressbar(progressBar, length, maxLength); StringBuilder Sb = new StringBuilder(new String(' ', length)); while (true && CancelOperation == false && hashes.Count > 0) { String value = Sb.ToString(); ulong calculatedHash = CalculateHash(hashType, $"{characterStartTB.Text}{value}"); if (hashes.Contains(calculatedHash)) { UpdateTextbox($"{characterStartTB.Text}{value}"); hashes.Remove(calculatedHash); if (hashes.Count == 0) { if (progressBar.InvokeRequired) { progressBar.Invoke((MethodInvoker) delegate { progressBar.Close(); }); } return; } } foreach (var line in characterStartTB.Lines) { ulong calculatedHash2 = CalculateHash(hashType, $"{line}{value}"); if (hashes.Contains(calculatedHash2)) { UpdateTextbox($"{line}{value}"); hashes.Remove(calculatedHash2); if (hashes.Count == 0) { if (progressBar.InvokeRequired) { progressBar.Invoke((MethodInvoker) delegate { progressBar.Close(); }); } return; } } } if (value.All(item => item == lastChar)) { break; } // Add one: aaa -> aab -> ... aaz -> aba -> ... -> zzz for (int i = length - 1; i >= 0; --i) { if (Sb[i] == ' ') { Sb[i] = '/'; break; } else if (Sb[i] == '/') { if (UseNumbered) { Sb[i] = '0'; } else { if (UseUppercase) { Sb[i] = 'A'; } else { Sb[i] = 'a'; } } break; } else if (Sb[i] == '0') { Sb[i] = '1'; break; } else if (Sb[i] == '1') { Sb[i] = '2'; break; } else if (Sb[i] == '2') { Sb[i] = '3'; break; } else if (Sb[i] == '3') { Sb[i] = '4'; break; } else if (Sb[i] == '4') { Sb[i] = '5'; break; } else if (Sb[i] == '5') { Sb[i] = '6'; break; } else if (Sb[i] == '6') { Sb[i] = '7'; break; } else if (Sb[i] == '7') { Sb[i] = '8'; break; } else if (Sb[i] == '8') { Sb[i] = '9'; break; } else if (Sb[i] == '9') { if (UseUppercase) { Sb[i] = 'A'; } else { Sb[i] = 'a'; } break; } else if (Sb[i] == 'Z') { Sb[i] = 'a'; break; } else if (Sb[i] != lastChar) { Sb[i] = (Char)(Sb[i] + 1); break; } else { Sb[i] = ' '; } } } } progressBar.Close(); }