Encription/Decription code

I'm hoping someone can give me some insight. I am very new to C++ programing and could use some guidance. I am trying to make a program to take a line of text from a file encrypt it and send it back to a file. Then, at the users request, get the encrypted code and decrypt it. I am not finished writing it, but I wanted to test what I have finished. I cannot get it to compile because of linking errors having to do with my user defined functions. I am writing this in MS VS 2010 (I have made sure that I chose the consol application).

#include <cstring>
#include <string>
#include <iostream>
#include <fstream>
#include <cctype>

using namespace std;

void encryptKeyMap (string, char&, int&);
void decryptKeyMap (string, char&, int&);
//void cyption (string&, string&, string&, int&, int, char, char);

int main ()
{
char run = 'y', choice = 'y';
char encryptMap [128];
char decryptMap [128];
int encryptMapLength = 0, decryptMapLength = 0;
string password;
string cryption;
string inText, outText;
ifstream inFile;
ofstream outFile;

do
{
cout << "Would you like to encrypt or decrypt a file?" << endl;
cout <<"If you would like to, enter ""Y"", if not enter ""Q"": ";
cin >> run;
run = tolower (run);

if (run == 'y')
{
cout << endl << "If you would like to encrypt a file enter ""E""" << endl;
cout << "If you would like to decrypt a file enter ""D""";
cout << endl << "Enter your selection: ";
cin >> choice;
choice = tolower (choice);
cout << endl;

if (choice == 'e')
{
cout << endl << "Enter the exact address of the file that you would like to encrypt" << endl;
cin >> inText;
inFile.open (inText);
getline (inFile, inText);

cout << """" << inText << """" << endl << "This will be encrytpted" << endl;
cout << endl << "Enter the exact address of the location for the file that you would " << endl
<< "like save the encyption to" << endl;
cin >> outText;
inFile.open (outText);
cout << "Enter a password to encrypt your file: ";
cin >> password;
encryptKeyMap (password, encryptMap [128], encryptMapLength);
outFile << outText;
}

if (choice == 'd')
{
cout << endl << "Enter the exact address of the file that you would like to decrypt" << endl;
cin >> inText;
inFile.open (inText);
getline (inFile, inText);
cout << """" << inText << """" << endl << "This will be decrytpted" << endl;
cout << endl << "Enter the exact address of the location for the file that you would " << endl
<< "like save the encyption to" << endl;
cin >> outText;
inFile.open (outText);
cout << "Enter your password to decrypt the file, the password must be the" <<
" same as the one used to encrypt the file: ";
cin >> password;
decryptKeyMap (password, decryptMap [128], decryptMapLength);
}

//cyption (inText, outText, cryption, decryptMapLength, encryptMapLength, encryptMap [128], decryptMap [128]);
}

if (run == 'q')
break;

else
{
cout << "You entered an invalid selection, try again" << endl;
run = 'y'; }
}
while (run == 'y');

inFile.close ();
outFile.close ();
}
void encryptKeyMap (string password, char encryptMap [128], int& encryptMapLength)
{
int position = 0, passLength;
passLength = password.length ();
bool isupper (password [position]);

for (position = 0; position <= passLength; position++)
{
if (true)
{ encryptMap [encryptMapLength] = password [position] - 'A';
encryptMapLength++; }
else if (false)
{ encryptMap [encryptMapLength] = password [position] - 'a';
encryptMapLength++; }
else
{
encryptMap [encryptMapLength] = password [position];
encryptMapLength++; }
}
}

void decryptKeyMap (string password, char decryptMap [128], int& decryptMapLength)
{
int passLength, position = 0;
passLength = password.length ();
bool isupper (password [position]);
ifstream inFile;
ofstream outFile;

for (position = 0; position <= passLength; position++)
{
if (true)
{ decryptMap [decryptMapLength] = (password [position] - 'A') - 26;
decryptMapLength++; }
else if (false)
{ decryptMap [decryptMapLength] = (password [position] - 'a') - 26;
decryptMapLength++; }
else
{ decryptMap [decryptMapLength] = password [position];
decryptMapLength++; }
}
}
//void cyption (string& inText, string& outText, string& cryption, int& decryptMapLength, int& encryptMapLength, char encryptMap [128], char decryptMap [128])
//{

//}

ERRORS:
1>------ Build started: Project: cypher, Configuration: Debug Win32 ------
1>second shot.obj : error LNK2019: unresolved external symbol "void __cdecl decryptKeyMap(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char &,int &)" (?decryptKeyMap@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AADAAH@Z) referenced in function _main
1>second shot.obj : error LNK2019: unresolved external symbol "void __cdecl encryptKeyMap(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char &,int &)" (?encryptKeyMap@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AADAAH@Z) referenced in function _main
1>C:\Users\Tom\Documents\School\Structured Programming with Lab\Week 7\Lab\cypher\Debug\cypher.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It's simple. You declared and used these functions but you did not define their implementations:
1
2
void encryptKeyMap (string, char&, int&);
void decryptKeyMap (string, char&, int&);


Hint: Know and understand your data types!
I'm still not tracking. I used void as the function type becuase there is more than one data type being passed, and i listed the data types of the variables that I am passing. I think my mistake must be with the string or character array, but I have no idea what I did wrong.
Add this and the code will compile and link correctly (does not mean it will do what you intended :P ):
1
2
void encryptKeyMap (string s, char& c, int& i) {}
void decryptKeyMap (string s, char& c, int& i){}
I kept messing with it and think I may have discovered what I was doing wrong. I changed the function prototype to:
1
2
void encryptKeyMap (string, char [], int&);
void decryptKeyMap (string, char [], int&);


and the function call to
1
2
encryptKeyMap (password, encryptMap, encryptMapLength);
encryptKeyMap (password, encryptMap, encryptMapLength);


and the function to
1
2
void encryptKeyMap (string password, char encryptMap [128], int& encryptMapLength)
void decryptKeyMap (string password, char decryptMap [128], int& decryptMapLength)


I don't know if this is correct, but it doesn't hate me now
I have another problem now. I want to identify characters from a string as capitals, lowwer case, or other. I'm tryig to use the functions isupper and islower to change the value of a bool variable and perform a calculation depending on the true/false state of the bool function. But the state doesn't seem to ever change from true.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int position = 0, passLength; 
	passLength = password.length ();

	do
	{
		bool isupper (password [position]);
		bool islower (password [position]);
		if (isupper == true)
		{	encryptMap [encryptMapLength] = password [position] - 'A';
			encryptMapLength++;
			position++;		}
		else if (islower == true)
		{	encryptMap [encryptMapLength] = password [position] - 'a';
			encryptMapLength++;
			position++;		}
		else
		{	encryptMap [encryptMapLength] = password [position];
			encryptMapLength++;
			position++;		}
				
	} while (position < passLength);


why?
bool isupper (password [position]);
bool islower (password [position]);

is that supposed to be your bool variables? the only thing could think of is that you think the isupper(char) function will overlap with your bool variable because you named it the same, but that isn't how it works.
Topic archived. No new replies allowed.