Skip to content

Commit

Permalink
Update pwa.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrophobis authored Mar 27, 2024
1 parent 282de07 commit 1e71d1c
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions pwa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace std;

void generateCombinations(const string& charSet, int maxLength, const string& password, string& currentString, int& guesses, int lowercaseCount, int numSymbolCount) {
void generateCombinations(const string& charSet, int maxLength, const string& password, string& currentString, int& guesses) {
static auto start = chrono::steady_clock::now();

if (currentString == password) {
Expand All @@ -16,37 +16,21 @@ void generateCombinations(const string& charSet, int maxLength, const string& pa
}

for (char c : charSet) {
currentString.push_back(c);
++guesses;

// Ensuring the first character is a capital letter
if (currentString.length() == 1 && !isupper(c)) {
currentString.pop_back();
// Ensure the first character is a capital letter
if (currentString.empty() && !isupper(c)) {
continue;
}

currentString.push_back(c);
++guesses;

// Checking if the current character is a lowercase letter or a number/symbol
if (islower(c)) {
lowercaseCount++;
} else if (!isalpha(c)) {
numSymbolCount++;
}

// Checking if the length of the currentString is within the maxLength limit
// Check if the length of the currentString is within the maxLength limit
if (currentString.length() <= maxLength) {
// Generating combinations with different ratios of lowercase letters to numbers/symbols
if (lowercaseCount < currentString.length() / 2 && numSymbolCount < currentString.length() / 2) {
generateCombinations(charSet, maxLength, password, currentString, guesses, lowercaseCount, numSymbolCount);
}
generateCombinations(charSet, maxLength, password, currentString, guesses);
}

// Undoing the changes for the next iteration
// Remove the last character to try the next combination
currentString.pop_back();
if (islower(c)) {
lowercaseCount--;
} else if (!isalpha(c)) {
numSymbolCount--;
}
}
}

Expand All @@ -64,10 +48,8 @@ int main() {

string currentString;
int guesses = 0;
int lowercaseCount = 0;
int numSymbolCount = 0;

generateCombinations(charSet, maxLength, password, currentString, guesses, lowercaseCount, numSymbolCount);
generateCombinations(charSet, maxLength, password, currentString, guesses);

return 0;
}

0 comments on commit 1e71d1c

Please sign in to comment.