Help with Simple encryption using c-style strings
I have been struggling with this piece of code for a few days now, i'm new to c++ and wanted to master this bit.
Here is the entire code. Ive marked where the code is missing.
Any ideas or suggestions are greatly appreciated...thanks...
Code:
#include <iostream>
using namespace std;
using namespace std;
const int alphaLen = 'Z'-'A'+1;
char upper( char c )
{
if ( c>='a' && c<='z' )
c=c+'A'-'a';
return c;
}
/*
cipherGenerate implicitly returns the generated cipher alphabet via
char cipherAlphabet [] parameter.
The function can assume that the associated cipherAlphabet array
is sufficently dimensioned to correctly store the cipher alphabet.
*/
void cipherGenerate(const char secretphrase[], char cipherAlphabet[])
{
cipherAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char str[20]; //not sure how to get length of cipherAlphabet and secretphrase //together?
strcat(str, secretphrase);
strcat(str, cipherAlphabet);
puts(str);
cipherAlphabet = str;
for (int i=0; i < strlen(cipherAlphabet); i++) {
for(int j=0; j < strlen(cipherAlphabet); j++) {
if(cipherAlphabet[i]=cipherAlphabet[j])
}
}
// MISSING CODE
} //End of function cipherGenerate
/*
encryptMessage implicitly returns the encryted message via
char encryptedMessage [] parameter.
The function can assume that the associated encryptedMessage array
is sufficently dimensioned to correctly store the encrypted message.
*/
void encryptMessage(const char secretPhrase[],
const char message[],
char encryptedMessage[] )
{
char cipherAlphabet[alphaLen];
cipherGenerate(secretPhrase, cipherAlphabet);
// MISSING CODE
} // end of function encryptMessage
/*
decryptMessage implicitly returns the decryted message via
char decryptedMessage [] parameter.
The function can assume that the associated decryptedMessage array
is sufficently dimensioned to correctly store the decrypted message.
*/
void decryptMessage(const char secretPhrase[],
const char encryptedMessage[],
char decryptedMessage[] )
{
char cipherAlphabet[alphaLen];
cipherGenerate(secretPhrase, cipherAlphabet);
//MISSING CODE
} // end function decryptMessage
int main(int argc, char * argv[])
{
char cipherAlphabet[alphaLen+1];
if ( argc<3 )
{
cout << argv[0] << " \"secret phrase\" \"message\"" << endl;
return 1;
}
cipherGenerate(argv[1], cipherAlphabet);
cipherAlphabet[alphaLen] = '\0';
cout << "The cipher alphabet is -" << cipherAlphabet << endl;
char * encryptedMessage = new char[strlen(argv[2])+1];
char * decryptedMessage = new char[strlen(argv[2])+1];
encryptMessage(argv[1], argv[2], encryptedMessage );
cout << "The encrypted message is -" << encryptedMessage<<endl;
decryptMessage(argv[1], encryptedMessage, decryptedMessage );
cout << "The decrypted message is -" << decryptedMessage<<endl;
delete encryptedMessage;
}