密码破译代码
#include <iostream>
#include <string>
void brute_force(std::string ¤t, int max_length, const std::string &charset, const std::string &target) {
if (current.length() == max_length) {
return;
}
for (char c : charset) {
current.push_back(c);
if (current == target) {
std::cout << "Password found: " << current << std::endl;
return;
}
brute_force(current, max_length, charset, target);
current.pop_back();
}
}
int main() {
std::string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
std::string target = "abc"; // 目标密码
std::string current;
brute_force(current, 50, charset, target); // 假设密码长度为3
return 0;
}