Skip to content

Commit

Permalink
pcoatl
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrophobis committed Mar 27, 2024
1 parent ef0d187 commit 5e2bc94
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"iostream": "cpp",
"ostream": "cpp",
"*.tcc": "cpp",
"string": "cpp"
"string": "cpp",
"atomic": "cpp"
},
"C_Cpp.errorSquiggles": "disabled"
}
89 changes: 89 additions & 0 deletions pcoatl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 490 Thousand Guessues Per Second
// aid! 0.2445s in 124 Thousand
#include <iostream>
#include <string>
#include <vector>
#include <chrono>
#include <openssl/sha.h>
#include <thread>
#include <atomic>
#include <sstream>
#include <iomanip>
#include <algorithm>

using namespace std;
using namespace chrono;

string sha256(const string &str) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);

stringstream ss;
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
ss << hex << setw(2) << setfill('0') << (int)hash[i];
return ss.str();
}

void attemptCombination(const string &charSet, int maxLength, const string &passwordHash, string currentString, atomic<bool> &found, atomic<long long> &guesses) {
if (found) return;

if (currentString.size() == maxLength) {
if (sha256(currentString) == passwordHash) {
found = true;
cout << "\nFound " << passwordHash << "(" << currentString << ")" << " with " << guesses << " guesses";
}
return;
}

for (char c : charSet) {
if (found) break;
guesses++;
attemptCombination(charSet, maxLength, passwordHash, currentString + c, found, guesses);
}
}

void workerThread(const string &charSet, int maxLength, const string &passwordHash, atomic<bool> &found, atomic<long long> &guesses, int start, int stride) {
for (int i = start; i < charSet.size() && !found; i += stride) {
string currentString(1, charSet[i]);
attemptCombination(charSet, maxLength, passwordHash, currentString, found, guesses);
}
}

int main() {
string charSet = "123abcdefghijklmnopqrstuvwxyz456ABCDEFGHIJKLMNOPQRSTUVWXYZ7890!@#$%^&*()-_=+[]{}|,'.<>?~";
string passwordHash;
int maxLength;

cout << "Hashed Input Password: ";
cin >> passwordHash;
cout << "Length Before Hashing: ";
cin >> maxLength;

atomic<bool> found(false);
atomic<long long> guesses(0);

auto start = high_resolution_clock::now();

int numThreads = thread::hardware_concurrency();
vector<thread> threads;
for (int i = 0; i < numThreads; ++i) {
threads.emplace_back(workerThread, ref(charSet), maxLength, ref(passwordHash), ref(found), ref(guesses), i, numThreads);
}

for (auto &t : threads) {
t.join();
}

auto end = high_resolution_clock::now();
duration<double, std::milli> duration_ms = end - start;

if (!found) {
cout << "Password not found within the specified length.\n";
}
cout << " in " << duration_ms.count() / 1000 << "s\n";

return 0;
}
Binary file added pwg/pcoatl
Binary file not shown.
Binary file modified pwg/pwh
Binary file not shown.
Binary file modified pwg/pwt
Binary file not shown.
6 changes: 3 additions & 3 deletions pwh.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 2.1 Million Guesses Per Second
// 2.2 Million Guesses Per Second
// aid! 0.260845 in 5.7 Million
#include <iostream>
#include <string>
Expand Down Expand Up @@ -32,11 +32,11 @@ void generateCombinations(const string& charSet, int maxLength, const string& pa
if (sha256(currentString) == password) {
auto end = steady_clock::now();
double elapsed_seconds = duration<double>(end - start).count();
cout << "Found " << password << "(" << currentString << ")" << " with " << guesses << " guesses" << " in " << elapsed_seconds << " seconds" << endl;
cout << "\n\n\n\n" << "Found " << password << "(" << currentString << ")" << " with " << guesses << " guesses" << " in " << elapsed_seconds << " seconds" << endl;
exit(0);
}

cout << sha256(currentString) << "\n";
//cout << sha256(currentString) << "\n";

for (char c : charSet) {
currentString.push_back(c);
Expand Down

0 comments on commit 5e2bc94

Please sign in to comment.