Can I make a nested loop out of this?
Ok, I'm making a multipurpose crypto calc, and I need a brute forcer for all possible caesar ciphers... I know exactly how to do it, and I could finish the code right now, only that would make it extremely cumbersome....
Look at the bolded (if it doesn't bold, I am talking about the for loop):
Code:
void caesar() //Return all possibilities of caesar encryption outcomes
{
char word[200];
int x, numchar1, numchar2, wordlength;
cout<<"Enter the word(s) you want to brute force with the Caesar Cipher in lower case." <<endl;
cin.getline(word, 200);
wordlength = strlen(word);
if(wordlength > 200)
{
cout<<"Your query was too long." <<endl;
caesar();
}
cout<<endl <<"Here is a list of possible solutions:" <<endl;
for(x = 0; x < wordlength; x++)
{
numchar1 = (int)word[x];
if(numchar1 == 122) //if the character is z, reset it to a
numchar2 = 97;
else if(numchar1 == 32) //space
numchar2 = 32;
else
numchar2 = numchar1 + 1; //change to the next letter in the alphabet
cout<<char(numchar2);
}
cout<<endl;
}
The last time I encountered nested loops, I had an extremely hard time comprehending it, and here is no different. I know that I want the bolded to loop 26 times, BUT each time I want numchar2 to equal numchar1 + (2, 3, 4, so on...), and I want to subtract the first if statement by one (go to a if you're currently at y this time, and x the next time, and w the time after that). Is that possible with a nested loop or am I better off just copying and pasting that 26 times and making necessary adjustments?