Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Artem Korshenko
- // cppstudio.com/post/8059
- // Linux C++11
- #include <iostream>
- #include <cmath> // pow() - function
- std::string input ( std::string str ) {
- std::cout << str;
- std::getline ( std::cin, str );
- return str;
- } // Python style
- int main() {
- std::string str_password;
- do {
- str_password = input ( "Enter password: " );
- if ( str_password.size() < 1 ) std::cout << "Please, enter password" << std::endl;
- } while ( str_password.size() < 1 );
- std::string str_chars;
- do {
- std::cout << "Type '+' to include... or press 'Enter' to skip" << std::endl;
- if ( input ( "Small chars: " ) == "+" ) str_chars += "qwertyuiopasdfghjklzxcvbnm";
- if ( input ( "Large chars: " ) == "+" ) str_chars += "QWERTYUIOPASDFGHJKLZXCVBNM";
- if ( input ( "Digits: " ) == "+" ) str_chars += "0123456789";
- if ( input ( "Symbols: " ) == "+" ) str_chars += " `~!@#$%^&*()_+=-][}{\';|:/.,<>?\\\"";
- if ( str_chars.size() < 1 ) std::cout << "Please, select characters" << std::endl;
- } while ( str_chars.size() < 1 );
- bool cycle = true;
- bool founded = false;
- int size_password = str_password.size();
- int size_chars = str_chars.size();
- int indexer[ size_password ];
- std::string str_bruteforce;
- str_bruteforce.resize ( size_password );
- for ( int i = 0; i < size_password; ++i ) indexer[i] = 0;
- std::cout << "Selected characters: " << str_chars << std::endl;
- std::cout << "Lenght of password: " << size_password << std::endl;
- std::cout << "Length of dictionary: " << size_chars << std::endl;
- std::cout << "Number of variants password: " << ulong ( std::pow ( size_chars, size_password ) ) << std::endl; // variants = library ^ password
- std::cout << "Please wait..." << std::endl;
- while ( true ) {
- for ( int i = size_password - 1; i >= 0; --i ) {
- if ( i != 0 ) {
- if ( indexer[i] == size_chars ) {
- indexer[i] = 0;
- indexer[i - 1]++;
- }
- }
- }
- for ( int i = 0; i < size_password; ++i ) str_bruteforce[i] = str_chars[indexer[i]];
- cycle = true;
- if ( str_bruteforce == str_password ) {
- std::cout << "You password: " << str_bruteforce << std::endl;
- cycle = false;
- founded = true;
- } if ( !cycle ) break;
- cycle = false;
- for ( int i = 0; i < size_password; ++i ) {
- if ( indexer[i] != size_chars - 1 ) {
- cycle = true;
- break;
- }
- } if ( !cycle ) break;
- indexer[ size_password - 1 ]++;
- }
- if ( !founded ) std::cout << "Error selected characters" << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement