I am writing a program that takes a string, and tries to create the copy of it using all possible combinations, like a sort of bruteforce.
Can someone help me? this is what i have:
#include <cstdlib>
#include <iostream>
#include <string>
usingnamespace std;
int main(int argc, char *argv[])
{
string a;
getline(cin,a);
char b[a.length()];
for(int l = 0;l<a.length();l++){
b[l]='a';
}
int num = 0;
for(int i = 0;i<a.length();i++){
for(int z = b[i];z<300;z++){
b[i]=z;
cout<<b<<endl;
}
if(a==b){
cout<<"works";
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
This doesnt work. I am trying to decode using the ansi table, witch every character of the array b starts at a, and add to it until it is 300.
Can someone point out what i am doing wrong?
Thanks in advance!
Doh! I like to use different variable names to you.
With this algorithm, anything more than 4 or 5 letters becomes a little too long to wait for. Reducing the scope of ASCII table values to check helped a little, but nothing to brag about.
I don't know how you'd modify this code to work for any given length string.