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

Pages: 123456
Your code...

My suggestion : It's better if you make an array...
And , you removed the cout command? The program prints nothing.
how you make that concurrent?


http://www.baptiste-wicht.com/2012/03/cpp11-concurrency-part1-start-threads/


Here is a tutorial on multithreading with c++11
it should work!? try the most recent??

also try poping couts in the code its fun to watch them tick
Compare :
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
bool crackpair (string &pair, string &crack, bool &pass)
{
string temppair, part1, part2, empty1;
for (int a = 0; a<45 ; a++)
  {
      part1 = singles [a];

     for (int b = 0; b<45 ; b++)
     {
     part2 = singles [b];

    temppair = part1+part2;
    cout<< temppair<<pair;

  if (pair == temppair)
{
   system ("pause");
   crack = temppair;

    return pass = true;
    break;
}


     }
if (pair == temppair)

    break;

  }

}



And the most recent :

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
bool crackpair (string &pair, string &crack, bool &pass)
{
string temppair, part1, part2, empty1;
for (int a = 0; a<45 ; a++)
  {
      part1 = singles [a];
      for (int b = 0; b<45 ; b++)
     {
     part2 = singles [b];
     temppair = part1+part2;
     if (pair == temppair)
  {
      crack = temppair;
      return pass =false;
      break;
  }
  }
  if (pair == temppair)

    break;

  }

}


Certainly you removed the cout command...
Last edited on
There you go mr iseeplusplus, and complete with awesome green color scrolling down thing, i know it slows it down but im not in a rush, besides my girlfreind likes it.

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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>

using namespace std;

string pair1,pair2,pair3,pair4,total,dash,crack1,crack2,crack3,crack4;

 bool pairone = true,pairtwo = true,pairthree = true, pairfour = 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, part1, part2, part3,part4,empty1;
for (int a = 0; a<45 ; a++)
  {
      part1 = singles [a];

     for (int b = 0; b<45 ; b++)
     {
     part2 = singles [b];
         for (int c = 0; c<45 ; c++)
         {
         part3 = singles [c];
             for (int d = 0;d<45;d++ )
             {
             part4 = singles [d];
            temppair = part1+part2+part3+part4;
            cout << temppair;

  if (pair == temppair)
{

   crack = temppair;

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


     }
if (pair == temppair)

    break;

  }
if (pair == temppair)

    break;
}
if (pair == temppair)

    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<<"-"<<pair2<<"-"<<pair3<<"-"<<pair4<<endl;
            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;
}
Wow! I now understand iseeplusplus algorithm completely... :)
Last edited on
@iseeplusplus, is there a way to thread without a special thread command?

yes mr jackson i removed it but its not so important, i was a little dissapointed with how fast it solved the problem with the cout command thing but i just popped it in there to see if it was working, you get the answer at the end (and the actual code in the beginning)
Last edited on
But...
part1+part2+part3+part4
Generally speaking , your string only contains two characters, and... certainly it may cause an infinite loop...
Last edited on
I told you about the letters, but you just would not listen...
at mr jackson...are you making this up as you go along??
You need to clean that up.

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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>

using namespace std;

string pair1,pair2,pair3,pair4,total,dash,crack1,crack2,crack3,crack4;

 bool pairone = true,pairtwo = true,pairthree = true, pairfour = 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, part1, part2, part3,part4,empty1;
    for (int a = 0; a<45 ; a++)
    {
         part1 = singles [a];

         for (int b = 0; b<45 ; b++)
         {
             part2 = singles [b];
             for (int c = 0; c<45 ; c++)
             {
                  part3 = singles [c];
                  for (int d = 0;d<45;d++ )
                  {
                      part4 = singles [d];
                      temppair = part1+part2+part3+part4;
                      cout << temppair;

                      if (pair == temppair)
                     {
                          crack = temppair; 

                          return pass =false;
                          system ("cls");
                          break;
                      }
                  }
                  if (pair == temppair)
                      break;
              }
              if (pair == temppair)
                  break;
          }
          if (pair == temppair)
              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<<"-"<<pair2<<"-"<<pair3<<"-"<<pair4<<endl;
            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;
}


For a start. And get rid of the redundancy.
Last edited on
whats this you talkin bout catfish and jackson, what letters would who not listen to? are you guys drinkning? im so confused
thats a lot more beautiful iseeplusplus, im testing the code now, its been running for a while now :)
Last edited on
huh it went in a complete loop and started again, what went wrong?
All I did was a little bit of indenting. If your using an IDE, auto-format.
Like I said before...
And your program is trying cracking 4 times...
ahh thats good to know, i will look for that, theres lots of compiler options i dont know about

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
#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, part1, part2, part3,part4;
    for (int a = 0; a<45 ; a++)
    {
         part1 = singles [a];

         for (int b = 0; b<45 ; b++)
         {
             part2 = singles [b];
             for (int c = 0; c<45 ; c++)
             {
                  part3 = singles [c];
                  for (int d = 0;d<45;d++ )
                  {
                      part4 = singles [d];
                      temppair = part1+part2+part3+part4;
                      cout << temppair;

                      if (pair == temppair)
                     {
                          crack = temppair;

                          return pass =false;
                          system ("cls");
                          break;
                      }
                  }
                  if (pair == temppair)
                      break;
              }
              if (pair == temppair)
                  break;
          }
          if (pair == temppair)
              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 << "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;
}


thats the redundancy gone, now to look for the flaw in the code
Last edited on
What? Any change?
lol heh, i forgot to change pair one sry i didnt understand you mr jackson dude

here we go BAM mr iseeplusplus ur prblm solvified

sr theres no threading i aint gotten that far yet, i had better go to sleep too, its twenty to two, i like coding its fun and its easiest when ,y girlfreinds sleeping

EDIT: i would love to see a snappier version


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
#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, part1, part2, part3,part4;
    for (int a = 0; a<45 ; a++)
    {
         part1 = singles [a];

         for (int b = 0; b<45 ; b++)
         {
             part2 = singles [b];
             for (int c = 0; c<45 ; c++)
             {
                  part3 = singles [c];
                  for (int d = 0;d<45;d++ )
                  {
                      part4 = singles [d];
                      temppair = part1+part2+part3+part4;
                      cout << temppair;

                      if (pair == temppair)
                     {

                          crack = temppair;

                          return pass =false;
                          system ("cls");
                          break;
                      }
                  }
                  if (pair == temppair)
                      break;
              }
              if (pair == temppair)
                  break;
          }
          if (pair == temppair)
              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;
            pair1=pair1+pair2+pair3+pair4;
            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;
}
Last edited on
Pages: 123456