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
|
#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;
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, 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;
}
}
int main ()
{
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)
{
bool pairone = true,pairtwo = true,pairthree = true, pairfour = true;
while (pairone != false)
{
cout << "cracking pair one" << endl;
pairone = crackpair(pair1,crack1,pairone);
}
total=crack1;
cout << total;
while (pairtwo != false)
{
cout<< "cracking pair two" << endl;
crackpair(pair2,crack2,pairtwo);
}
total=total+dash+crack2;
cout << total;
while (pairthree != false)
{
pairthree = crackpair(pair3,crack3,pairthree);
}
total=total+dash+crack3;
cout<< total;
while (pairfour != false)
{
pairfour = crackpair(pair4,crack4,pairfour);
}
total=total+dash+crack4;
cout << total <<endl;
}
break;
}
break;
cout << "the code was; "<< total<<"restart? y/n"<<endl;
}
}
}
return 0;
}
|