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;
}
|