/
lyapdy
/
Object_oriented_programming_cpp_318
Обзор
Документация
Войти
/
lyapdy
/
Object_oriented_programming_cpp_318
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lab6/task_1.cpp
96 строк
3 KB
danillyapunov
lab6com
11 янв 2026, 09:54
11 янв 2026, 09:54
7284f90
Код
Авторство
О чём код?
#include <iostream> #include <string> #include <vector> #include <algorithm> #include "task_1.h" #include "config.h" Bruteforce::Bruteforce(const std::string& pass, const std::string& char_set) : password_(pass), charset_(char_set) { std::sort(charset_.begin(), charset_.end()); charset_.erase(std::unique(charset_.begin(), charset_.end()), charset_.end()); } bool Bruteforce::brute() { std::cout << "Используется набор символов: " << charset_ << "\n"; std::cout << "Размер набора: " << charset_.size() << " символов\n"; for(int len = 1; len <= max_length_; ++len) { std::string current(len, charset_[0]); do { std::cout << "Проверяю: " << current << '\n'; if(current == password_) return true; int pos = len - 1; while(pos >= 0) { size_t current_idx = charset_.find(current[pos]); if(current_idx == charset_.size() - 1) { current[pos] = charset_[0]; pos--; } else { current[pos] = charset_[current_idx + 1]; break; } } if(pos < 0) break; } while(true); } return false; } constexpr int Bruteforce::getMaxLength() { return max_length_; } void BruteforceRunner::show_menu() const { std::cout << "\n*** Настройки перебора ***\n"; std::cout << "Выберите типы символов:\n"; std::cout << "1. Только цифры\n"; std::cout << "2. Строчные латинские буквы\n"; std::cout << "3. Прописные латинские буквы\n"; std::cout << "4. Цифры + строчные буквы\n"; std::cout << "5. Цифры + прописные буквы\n"; std::cout << "6. Все перечисленные символы\n"; } std::string BruteforceRunner::choose_charset(int choice) const { switch(choice) { case 1: return "0123456789"; case 2: return "abcdefghijklmnopqrstuvwxyz"; case 3: return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; case 4: return "0123456789abcdefghijklmnopqrstuvwxyz"; case 5: return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; case 6: return "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; default: return "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; } } void BruteforceRunner::run() { std::string user_password; std::cout << "Введите пароль (до " << Bruteforce::getMaxLength() << " символов): "; std::cin >> user_password; if(user_password.length() > Bruteforce::getMaxLength() || user_password.empty()) { std::cerr << "Ошибка: Длина пароля должна быть от 1 до " << Bruteforce::getMaxLength() << " символов.\n"; return; } show_menu(); int choice; std::cout << "Ваш выбор: "; std::cin >> choice; std::string charset = choose_charset(choice); Bruteforce bf(user_password, charset); if(bf.brute()) { std::cout << "Пароль успешно подобран!\n"; } else { std::cout << "Пароль не найден.\n"; } }