What is the secret to becoming the greatest programmer in the whole wide world?

Pages: 123456
Again, your problem is "The program cannot crack the string", right?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool crackpair (string &pair, string &crack, bool &pass) {

    for (int a = 0; a<45 ; a++) 
         for (int b = 0; b<45 ; b++) 
             for (int c = 0; c<45 ; c++)
                  for (int d = 0;d<45;d++ ){
                      string temppair = singles[a]+singles[b]+singles[c]+singles[d];
                      cout << temppair;
                      if (pair == temppair) {
                          crack = temppair;
                          return pass = false;
                          system ("cls");
                          break;
                      }
                  }    
}


This is equivalent to the way you had it. But I don't think it does what you think it does.

    slctr = 1+(rand()%44);
    slctr2 = 1+(rand()%44);


Your getting a number from between 1 and 44 with this. What about 0?
Last edited on
Get rid of 1. Replace '44' with '45'
Last edited on
actually my head was still in pairs itssimple but dumb and expected of tired mind; i got four numbers and four four loops...i need eight!!

oh yeah and thats obvious now i see it.

i hate 0...no i just forgot the plus1 was there
Last edited on
You want : eight-character string and use 8 character-loops to crack it?
Or anything else? :/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bool crackpair (string &combo) {

    for (int a = 0; a<45 ; a++) 
         for (int b = 0; b<45 ; b++) 
             for (int c = 0; c<45 ; c++)
                  for (int d = 0;d<45;d++ )
                      for (int e = 0; e<45 ; e++) 
                          for (int f = 0; f<45 ; f++) 
                              for (int g = 0; g<45 ; g++)
                                  for (int h = 0;h<45;h++ )
                                      if ( singles[a] + singles[b]
                                          +singles[c] + singles[d]
                                          +singles[e] + singles[f]
                                          +singles[g] + singles[h] 
                                          == combo
                                      )
                                          return true;
    return false;
}


Your problem may be that it might take you a while to do over 16 trillion loops.
Last edited on
there she is working like she is supposed too...
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>

using namespace std;

string pair1,pair2,pair3,pair4,total,dash,crack1;

 bool pairone = true;

string singles[45] = {"1","2","3","4","5","6","7","8","9","0",
"q","w","e","r","t","y","u","i","o",
"p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m",
"!","£","$","%","^","&","*","(",")"};

string getrandpair ()
{
    string pair,p1,p2;
    int slctr,slctr2;
    slctr = 1+(rand()%44);
    slctr2 = 1+(rand()%44);
    p1 = singles [slctr];
    p2 = singles [slctr2];
    return pair = p1+p2;
}

bool crackpair (string &pair, string &crack, bool &pass)
{
    string temppair;
    for (int a = 0; a<45 ; a++)
      for (int b = 0; b<45 ; b++)
        for (int c = 0; c<45 ; c++)
          for (int d = 0;d<45;d++ )
            for (int e = 0; e<45; e++)
              for (int f = 0; f<45;f++)
               for (int g = 0; g<45;g++)
                 for (int h = 0; h<45;h++)
                { temppair =singles[a]+ singles[b]+singles[c]+singles[d]+singles[e]+singles[f]+singles[g]+singles[h];
                      cout << temppair;

                      if (pair == temppair)
                     {

                          crack = temppair;

                          return pass =false;
                          system ("cls");
                          break;
                      }
                  }

      }




int main ()

{
system ("color a");
srand(time(0));

dash = "-";
int refresh;
bool quit = true, restart = true;

while (quit != false)
{
    cout << "type 1 to create new code or type 2 to quit "<<endl;
    cin >> refresh;
    switch (refresh)
    {
        case 2:
        quit = false;
        break;
        case 1:
        while (restart != false)
        {
           pair1 = getrandpair();
            pair2 = getrandpair();
            pair3 = getrandpair();
            pair4 = getrandpair();
            cout << pair1<<dash<<pair2<<dash<<pair3<<dash<<pair4<<endl;

            cout << pair1;
            cout << "press 1 to begin decoding and 2 to quit"<< endl;
            cin >> refresh;

                   switch (refresh)
                   {
                   case 2:
                   restart = false;
                   break;
                   case 1:
                   while (restart != false)
                   {
                    while (pairone != false)
                    {
                        crackpair(pair1,crack1,pairone);
                    }

                    restart = false;
                   }
                   break;
                   }
         restart = true;
        break;
        cout << "the code was; "<< crack1<<"restart? y/n"<<endl;


    }

}
}
return 0;
}


spoonlicker wishes he was me.
@iseeplusplus; yeah thats why we want concurence right? or like i did and just split it up into pairs... but i wasnt allowed to do that

its 458!

5mins and still 111999!
Last edited on
Infinite program loop (° °) Now, example?
1
2
3
4
                    while (pairone != false)
                    {
                        crackpair(pair1,crack1,pairone);
                    }

How many characters are there in pair1?

5mins and still 111999!

It won't be possible while printing out every guess. You may also like to reduce the number of symbols in your set.
Last edited on
just two, oh wait now lol 4 pairs! or 8 digits!!, its called pair1 from the last code where i paired em up to save time and then i butchered it to make this code. i meant 5 mins and still 11199999!! now today i suss out threading :)
do i install c++11?
need boost i downloaded it but dont know how to link it, besides the tutorials are way complicated
Last edited on
http://nuwen.net/mingw.html

Command line, you'll find instructions text file after you install it. Contains Boost.
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>

using namespace std;

vector <string> spair;//Edited
string dash = "-", crack2;

long tstart, tend; //Clock variables 


string singles[45] = {"1","2","3","4","5","6","7","8","9","0",
"q","w","e","r","t","y","u","i","o",
"p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m",
"!","£","$","%","^","&","*","(",")"};

char chrSingles[45] = {'1','2','3','4','5','6','7','8','9','0',
'q','w','e','r','t','y','u','i','o',
'p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',
'!','£','$','%','^','&','*','(',')'};

string getrandpair (unsigned int nlength){
		string st;st.erase();

		if(!nlength)nlength++;
		for(int i = 0;i < nlength;i++)st += singles[rand() % 45];
	   
		return st;
}



bool crackpair (string &stpair, string &crack, int nlen){if(!nlen)return false;

	int *digit = new int[nlen];
	string stemp;stemp.erase();
	for(int i =0;i < nlen;i++)digit[i] = -1; //Because : (++) code first

	bool exit = false;
	int nLevel;
	int nchrCount = 0; //Number of (stemp) characters

stemp += singles[0]; //Allocates a character first

tstart = clock(); //Clock starts
while(stpair != stemp){

	digit[0]++;stemp[0] = chrSingles[digit[0]];

	if(digit[0] == 45){
		digit[0] = -1;nLevel = 1; //Resets value, switch to the next digit level
		if(!nchrCount){nchrCount = 2;stemp += singles[0];} //Exception : Allocates the second character

	Counting: 
	digit[nLevel]++;stemp[nLevel] = chrSingles[digit[nLevel]];
	if(digit[nLevel] == 45){
		digit[nLevel] = -1;nLevel++; //Next level


		if(nLevel >= nchrCount){nchrCount++;stemp+=singles[0];}  // Allocates a character if needed
	
	goto Counting;}}

	cout << stemp; //Prints the current value

}

tend = clock(); //End clock
crack = stemp; //Result
delete digit; //Free memory
return true; //Always
}




int main (){srand(time(0));

int refresh = 0, npair = 0, nlen = 0;
bool quit = false, restart = true;


while (1){
	npair = nlen = 0;
	
	while(refresh != 1 && refresh != 2){
    cout << "Type 1 to create new code or type 2 to quit : ";
    cin >> refresh;}
	cout << endl;

	if(refresh == 2)break; //Quit

	while(!npair){
    cout << "How many string units : ";
    cin >> npair;}
	cout << endl;
///////////////////////////////////////////////////////////////////////////////
spair.clear();for(int i = 0;i < npair;i++)spair.push_back(crack2);
////////////////////////////////////////////////////////////////////////////////
	while(!nlen){
    cout << "Length of each string : ";
    cin >> nlen;}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
    switch (refresh)
    {
        case 2: quit = true;break;

        case 1:
       
		for(int i = 0;i < npair;i++){
		spair[i] = getrandpair(nlen); //Get...
		cout << spair[i]; if(i != npair - 1)cout << dash;}

		cout << endl << endl; //Next line
		
		for(int a = 0;a < npair;a++){ //Start :
		cout << spair[a]; 

		refresh = 0;
	while(refresh != 1 && refresh != 2){
        cout << ": Press 1 to begin decoding and 2 to quit"<< endl;
			 cin >> refresh;}

                   switch (refresh)
                   {
                   case 2: refresh = 0;cout << endl;goto Quit;break;
                   
				   case 1 : crackpair(spair[a], crack2, nlen);
					cout << endl << endl << "Result : " << crack2 << endl;
					cout << "Time : " << (tend - tstart) / 1000.0f << endl << endl;

					break;

				   }

		}

Quit : nlen = nlen; //Crazy random code... :P
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

return 0;
}

Edit : Changed a bit...

Enjoy... :) :D ^.^ :D
Last edited on
Is this right?

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <ctime>
#include <iostream>
#include <limits>
#include <utility>
#include <vector>

static const std::vector <char> __charset = {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!',
    '@', '#', '$', '%', '^', '&', '*', '?', '<', '>', '~'
};

template <typename T>
static T random(T min = std::numeric_limits<T>::min(),
                T max = std::numeric_limits<T>::max())
{
    static int seeded;
    if (!(seeded)) {
        srand((unsigned)time(0));
        seeded = 1;
    }
    return min + T(((max - min) * rand()) / (RAND_MAX + 1.0));
}

static char random_char()
{
    return __charset[random<size_t>(0, __charset.size())];
}

static std::pair <char, char> random_pair()
{
    return { random_char(), random_char() };
}

static std::vector < std::pair <char, char> > random_pairs()
{
    return { random_pair(), random_pair(), random_pair(), random_pair() };
}

static void guess_pair(std::pair <char, char> pair)
{
    for (char c : __charset) {
        if (c == pair.first) {
            for (char d : __charset) {
                if (d == pair.second)
                    std::cout << c << d;
            }
        }
    }
}

static void guess(std::vector < std::pair <char, char> >& pairs)
{
    guess_pair(pairs[0]);
    std::cout << '-';
    guess_pair(pairs[1]);
    std::cout << '-';
    guess_pair(pairs[2]);
    std::cout << '-';
    guess_pair(pairs[3]);
    std::cout << std::endl;
}

int main()
{
    std::vector < std::pair <char, char> > pairs = random_pairs();
    std::cout << pairs[0].first << pairs[0].second << '-'
              << pairs[1].first << pairs[1].second << '-'
              << pairs[2].first << pairs[2].second << '-'
              << pairs[3].first << pairs[3].second << std::endl;
    clock_t start = clock();
    guess(pairs);
    std::cout << "Solved in " << clock() - start << " ms." << std::endl;
    return 0;
}
Last edited on
ahh, so i could of made a function to search each of the digits all at the same time by having the function called through a loop, is that threading??
I was thinking guess the whole combination at once; get feedback wether the whole combination is correct. How often can you crack a password 2 entries at a time?
what do you mean?
i guess checking each digit is correct or not is similar to what i did in pairs, i could have got a loop to do the all at once i guess
I have an example above.
Look at the example. And now...zzz :)

Have you tested it?
Last edited on
Unfortunately MinGW 4.7.2 doesn't implement std::thread.

Damn it's ugly.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <algorithm>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <ostream>
#include <random>
#include <stdexcept>
#include <thread>
#include <utility>
#include <vector>

namespace {

const std::vector<char> availableElements {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    '!', '@', '#', '$', '%', '^', '&', '*', '?', '<', '>', '~'
};

const std::vector<char>::size_type defaultCombinationSize = 8;
std::vector<char> elusiveCombination;

} // namespace

namespace src {

std::vector<char> createRandomCombination(std::vector<char>::size_type vcs = ::defaultCombinationSize)
{
    std::default_random_engine dre(std::chrono::system_clock::now().time_since_epoch().count());
    std::uniform_int_distribution<std::vector<char>::size_type> uid(0, ::availableElements.size() - 1);
    auto getRandomIndex = std::bind(uid, dre);
    std::vector<char> vc(vcs);

    std::generate(vc.begin(), vc.end(), [&getRandomIndex]() -> char {
        return ::availableElements.at(getRandomIndex());
    });

    return vc;
}

std::ostream & operator << (std::ostream &os, const std::vector<char> &vc)
{
    for (char c: vc)
        os << c;

    return os;
}

std::pair<std::vector<char>, bool> first(std::vector<char> vc)
{
    if (vc.size() == ::defaultCombinationSize)
        return std::make_pair(std::vector<char>{}, false);

    vc.push_back(::availableElements.front());
    return std::make_pair(vc, true);
}

std::pair<std::vector<char>, bool> next(std::vector<char> vc)
{
    if (vc.back() == ::availableElements.back())
        return std::make_pair(std::vector<char>{}, false);

    vc.back() = *++std::find(::availableElements.begin(), ::availableElements.end(), vc.back());
    return std::make_pair(vc, true);
}

void whinyChecker(const std::vector<char> &candidateCombination, std::ostream &os = std::cout)
{
    if (candidateCombination.size() != ::elusiveCombination.size())
        throw std::length_error("candidateCombination and ::elusiveCombination are not the same size.");
    else
    if (std::equal(candidateCombination.begin(), candidateCombination.end(), ::elusiveCombination.begin()))
    {
        os << ::elusiveCombination << " == " << candidateCombination << std::endl;
        throw std::logic_error("Solution was found, so why go on?");
    }
    else
        os << ::elusiveCombination << " != " << candidateCombination << std::endl;
}

void whinyBacktrack(const std::vector<char> &target, const std::vector<char> &built)
{
    if (target.size() == built.size())
    {
        whinyChecker(built);
        return;
    }

    auto possibleSolution = first(built);

    while (possibleSolution.second)
    {
        whinyBacktrack(target, possibleSolution.first);
        possibleSolution = next(possibleSolution.first);
    }
}

std::list<std::vector<char>> generateLimits()
{
    std::list<std::vector<char>> lvc;

    for (char c: ::availableElements)
    {
        std::vector<char> vc;

        vc.push_back(c);

        while (vc.size() < ::defaultCombinationSize)
            vc.push_back(::availableElements.back());

        lvc.push_back(vc);
    }

    return lvc;
}

} // namespace src

using src::operator<<;

#ifndef GCC_ACTUALLY_IMPLEMENTS_THREADS

int main()
{
    ::elusiveCombination = src::createRandomCombination();
    src::whinyBacktrack(src::generateLimits().back(), {});
}

#else

int main()
{
    ::elusiveCombination = src::createRandomCombination();

    std::list<std::thread> lt;

    for (const std::vector<char> &vc: src::generateLimits())
        lt.push_back(std::thread(src::whinyBacktrack, std::cref(vc), {}));

    for (std::thread &t: lt)
        t.join();
}

#endif 
Last edited on
Now I think that my example code above is outdated. But, have you tested my code above yet? :)
But, no problem. Only thread-thread feature is missing. I'll add, compile and rebuild the code again, just use the multi-threading at a proper place... And...don't use too much... :)
Expect me!!!
Last edited on
Pages: 123456