Still no answers, Need help clock up charecters!

Basically this program imitates the stereo-typicle visual output of a password cracker but i need help with something.
This program could be used for a game or such, but for now i just want to get the letter cycling working properly and it's running through a console but i'm having a little trouble.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

short i;
short temp = 32;
short k;
vector<char> word;

int main()
{
    word.push_back('!');
    while(true){
        i = ( word.size() - 1);
            while(temp < 127){
            word[i] = static_cast<char>(temp);
            for(short a = 0; a < word.size(); a++)
            cout << word[a];
            cout << "\t\n";
            temp++;
        }
        
        
            k = static_cast<short>(word[i]);
            if(k == 126){
                word[i] = ' ';
                if(i == 0){
                    word.push_back(' ');}
                else
                i--;
            }
            else{
                k++;
                word[i] = static_cast<char>(k);
                temp = 32;
                }
            system("pause");
        }
}
 


I added a console pause at the end so i could see what happened on out put and the 1st loop it cycles through all letters+symbols, 2nd loop it adds SP ' ' to the front which i expect and then cycles through all letters on right hand side, but on the 3rd loop the SP ' ' DOES NOT change to the '!' like i expect.

I'm not sure why this is happening and i've deliberately made most my variables global because earlier i had problems due to the scope.
Does anybody know what the problem is with my program and possibly a Simple way that this may be fixed please? I'm hoping that i may have just made a simple syntax error or such that i've not noticed.

Thanks to anyone that may be able to help.
Consider writing the program with small, easy to understand, functions.

For example, this will generate by brute force all possible permutations of all possible printable characters. Start with something simple like this, and then add intelligence, bit by bit, to make the password cracker.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
inline std::size_t factorial( std::size_t n )
{ return n==0 ? 1 : n * factorial(n-1) ; }

void print_unique_permutations( std::string str )
{
    std::unordered_set<std::string> permutations ;
    for( std::size_t i = 0 ; i < factorial( str.size() ) ; ++i )
    {
        permutations.insert(str) ;
        std::next_permutation( str.begin(), str.end() ) ;
    }
    for( const std::string& s : permutations )
    {
        static int n = 0 ;
        std::cout << ++n << ". " << s << '\n' ;
        if( n%100 == 0 ) std::cin.get() ;
    }
}

void generate_and_print( const std::string& prefix, std::size_t sz, const std::vector<char>& char_set )
{
    if( sz == 0 ) print_unique_permutations(prefix) ;
    else for( char c : char_set ) generate_and_print( prefix+c, sz-1, char_set ) ;
}

void generate_and_print( std::size_t sz, const std::vector<char>& char_set )
{ generate_and_print( "", sz, char_set ) ; }

std::vector<char> printable_chars()
{
    enum { MIN = std::numeric_limits<char>::min(),
            MAX = std::numeric_limits<char>::max() } ;
    std::vector<char> chars ;
    for( int c = MIN ; c <= MAX ; ++c ) if( std::isprint(c) ) chars.push_back(c) ;
    return chars ;
}

int main()
{
    std::cout.sync_with_stdio(false) ;
    const std::vector<char> char_set = printable_chars() ;

    enum { MIN_LENGTH = 6, MAX_LENGTH = 8 };
    for( std::size_t i = MIN_LENGTH ; i <= MAX_LENGTH ; ++i )
          generate_and_print( i, char_set ) ;
}
Last edited on
I may have forgotten to mention I consider myself as quite a newbie but i'll do some research and try your suggestion out later. By research i mean i'll have to go over some of the statements and functions such as the .insert() i'm not familiar with and such.
It would be helpful if you could post links to where i may be able to find the appropriate information to help me understand some of the statement but if you can't the no worries!

Thanks for the help :)
Last edited on
Why did you open two different threads on this? I replied to your other thread already... go look at it. O_o
There's a reference page on this site... if you go there, you can probably find all of this.
Topic archived. No new replies allowed.