-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eac0759
commit c11a6cc
Showing
19 changed files
with
103 additions
and
57 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Test file | ||
// aid! 0.184227 in 9.95 Million | ||
// 56.9 Million Guesses Per Second | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <chrono> | ||
#include <thread> | ||
#include <atomic> | ||
|
||
using namespace std; | ||
using namespace chrono; | ||
|
||
atomic<bool> found(false); | ||
|
||
void generateCombinations(const string &charSet, int maxLength, const string &password, string currentString, int &guesses) { | ||
if (found) return; | ||
|
||
if (currentString == password) { | ||
found = true; | ||
cout << "Found " << password << " with " << guesses << " guesses" << endl; | ||
return; | ||
} | ||
|
||
for (char c : charSet) { | ||
if (found) return; | ||
|
||
currentString.push_back(c); | ||
++guesses; | ||
|
||
if (currentString.length() <= maxLength) { | ||
generateCombinations(charSet, maxLength, password, currentString, guesses); | ||
} | ||
|
||
currentString.pop_back(); | ||
} | ||
} | ||
|
||
int main() { | ||
string charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+[]{}|,'.<>?~"; | ||
string password; | ||
int maxLength; | ||
int guesses = 0; | ||
|
||
cout << "Password: "; | ||
cin >> password; | ||
|
||
cout << "Length: "; | ||
cin >> maxLength; | ||
|
||
auto start = high_resolution_clock::now(); | ||
|
||
vector<thread> threads; | ||
int numThreads = thread::hardware_concurrency(); | ||
|
||
for (int i = 0; i < numThreads; ++i) { | ||
threads.emplace_back(generateCombinations, cref(charSet), maxLength, cref(password), string(), ref(guesses)); | ||
} | ||
|
||
for (auto &t : threads) { | ||
t.join(); | ||
} | ||
|
||
auto end = high_resolution_clock::now(); | ||
duration<double> elapsed_seconds = end - start; | ||
cout << "Time elapsed: " << elapsed_seconds.count() << "s\n"; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <sstream> | ||
#include <openssl/sha.h> | ||
#include <iomanip> | ||
|
||
std::string sha256(const std::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); | ||
|
||
std::stringstream ss; | ||
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { | ||
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]); | ||
} | ||
return ss.str(); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 2) { | ||
std::cerr << "Usage: " << argv[0] << " <string_to_hash>\n"; | ||
return 1; | ||
} | ||
|
||
std::string input = argv[1]; | ||
std::string hashed = sha256(input); | ||
std::cout << "SHA256 hash of '" << input << "': " << hashed << std::endl; | ||
|
||
return 0; | ||
} |