Code:
//a caesar cipher is an old form of encryption that takes some text, //and offsets each letter by the same number of places in the //alphabet, like abcde with a key of +5 would be efghi
#include <iostream>
#include <cstring>
#include <cstdlib>
int main() //Return all possibilities of caesar encryption outcomes
{
char word[200], result[200];
int x, i, ztoa = 122, numchar1, numchar2, wordlength;
cout<<"Enter the word(s) you want to brute force with the Caesar Cipher in lower case." <<endl;
cout<<"It is VITAL that you add a space after the last word." <<endl;
cin.getline(word, 200);
if(wordlength == 200) // i don't care if this won't work, it's not my main problem
{
cout<<"Your query was too long. Some parts were omitted." <<endl;
}
cout<<endl <<"Here is a list of possible solutions:" <<endl;
for(x = 0; x < wordlength; x++)
{
numchar1 = (int)word[x]; //converts numchar1 to int so i can add and subtract according to the ascii chart
if(numchar1 == 122) //if the character is z
{
numchar2 = 97; //reset it to a
}
else if(numchar1 == 32) //if it's a space, leave it alone
numchar2 = 32;
else if(numchar1 == 32 || numchar1 == 97 || numchar1 == 98 || numchar1 == 99 || numchar1 == 100 || numchar1 == 101 || numchar1 == 102 || numchar1 == 103 || numchar1 == 104 || numchar1 == 105 || numchar1 == 106 || numchar1 == 107 || numchar1 == 108 || numchar1 == 109 || numchar1 == 110 || numchar1 == 111 || numchar1 == 112 || numchar1 == 113 || numchar1 == 114 || numchar1 == 115 || numchar1 == 116 || numchar1 == 117 || numchar1 == 118 || numchar1 == 119 || numchar1 == 120 || numchar1 == 121 || numchar1 == 122)
numchar2 = numchar1 + 1; //change to the next letter in the alphabet if the input is in the alphabet
if(numchar2 == 32 || numchar2 == 97 || numchar2 == 98 || numchar2 == 99 || numchar2 == 100 || numchar2 == 101 || numchar2 == 102 || numchar2 == 103 || numchar2 == 104 || numchar2 == 105 || numchar2 == 106 || numchar2 == 107 || numchar2 == 108 || numchar2 == 109 || numchar2 == 110 || numchar2 == 111 || numchar2 == 112 || numchar2 == 113 || numchar2 == 114 || numchar2 == 115 || numchar2 == 116 || numchar2 == 117 || numchar2 == 118 || numchar2 == 119 || numchar2 == 120 || numchar2 == 121 || numchar2 == 122)
{
result[x] = (char)numchar2; // if it returns all ascii for lowercase alphabet (don't ask me why, it wasn't working without this), put the result in character form inside the array currently being used by the for loop
}
}
cout<<result; //display the first result
while(result != word) //loop this until you hit the beginning word again
{
for(i = 0; i < wordlength; i++) //this loop repeats the first loop more or less, but now we have each in a comparable variable so it can be terminated once it hits the original
{
if(result[i] == 'z')
result[i] = 'a';
else if(result[i] == ' ')
result[i] = ' ';
else
result[i] = (char)((int)i + 1);
}
cout<<result; //display the result of whatever the variable is + 1 for each letter
}
main();
}
As you can see, the while loop does NOT undo the first loop in any way, shape, or form....