I'm trying to do a substitution cipher, but I cannot get it to output the translated code. This is what I have right now but I am wondering if I could use strstr to search for the letter in the encrypter key and output it that way. This is what I have
cout << endl << "Original Alphabet: ";
int x = 0;
for ( char i = 'A'; i <= 'Z'; i++)
{
original[x++] = i;
}
for (int i = 0; i < 26; i++)
{
cout << original[i];
}
//encrypted alphabet
int count;
cout << endl << "Encrypted: ";
for (count = 0; count < SUBCIPHER; count++)
{
inFile >> newAlpha[count];
}
for (int i = 0; i < 26; i++)
{
cout << newAlpha[i];
}
int count=0;
char decrypt[LINE_SIZE];
inFile.getline(decrypt, LINE_SIZE);
inFile >> decrypt;
while (inFile)
{
cout << endl << "\n ";
while (decrypt[count] != '\0')
{
cout << decrypt[count];
count++;
}
count = 0; //incrementer
int counter = 0; //increments newAlpha
cout << "\n";
while(toDecode[count] != '\0')
{
int lineLength;
lineLength = strlen(decrypt);
do
{
if(decrypt[count] == newAlpha[counter])
{
decrypt[count]= alphabet[counter];
cout << alphabet[counter];
}
elseif (decrypt[count] == ' ')
{
decrypt[charCount] == ' ';
}
else
{
counter++;
}
}while ( decrypt[count] < lineLength);
count++;
}
I tried this, but there's an overloaded error on the strstr.
1 2 3 4 5 6 7 8 9 10 11 12
int lineLength;
char *strPtr = NULL;
lineLength = strlen(toDecode);
for (counter=0;counter < lineLength; counter++)
{
strPtr = strstr(fixedSub[counter],toDecode[charCount]);
//?? not sure what to do here
if (strPtr != NULL)
break; // or here
}