Hi I am trying to find out what I am doing wrong with this code...I need it to load a file and encrypt it, print it, encrypt it again(decrypt it), print it then save it to another file. the original and the new file should be the same...Here is what I have so far (I'm not sure it's right since it won't compile) any help would be GREATLY appreciated.
#include <iostream> //includes library of terms that allows streams
#include <string> //includes library of terms that allows strings
#include <fstream> //includes library of terms that allow file I\O
using namespace std; // Basic library of terms
struct Message //defining structure called message
{
string message; // represents message itself
int key; // int to represent the key used to encrypt/decrypt the message
void encrypt(int charNumber);
void encrypt();
};
class Encrypt
{
private:
Message ms[10];//array of messages, max number of 10
int numMessages; // indicates the current number of messages in the array
public:
Encrypt(); //my default constructor
void addMessage(Message m); //takes in message and adds it to the array
void encrypt (int index); //takes in int and encrypts only the at that index in the array
void encrypt (); //takes in no parameters encrypts every message in array
void load(string filesname);//load func which takes in string and loads each message from that file into the array
void print(); //prints out each message (but not the keys)to the screen
void save(string filesname);//takes in a string and saves all of the messages to that file
};
int main()
{
Encrypt e;
e.load("file.txt"); //loads file
e.print(); //prints file
e.encrypt(); //encrypts file
e.print(); //prints encrypted file
e.save("filenew.txt"); //saves encrypted file to new location
e.encrypt(); //unencrypts file
e.print(); //prints file again(should be same as before encryption)
return 0;
}
void Message::encrypt(int charNumber)
{
message[charNumber] += key;
}
void Message::encrypt ()
{
for(int i = 0; i < message.size ; i++)
{
encrypt(i);
}
key *= -1;
}
void Encrypt::encrypt(int index)
{
ms[index].encrypt();
}
void Encrypt::addMessage(Message m)
{
if(numMessages<10)
{
Messages[numMessages].key = m.key;
Messages[numMessages].mess = m.mess;
numMessages ++;
}
}
void Encrypt::encrypt(int index) // this function changes the message into ascii numbers
{
int temporaryKey.ms[index].key;
string temp = ms[index].part;
for(i = 0; i < temporary.size(); i++)
{
int ascii = temporary[i];
ascii = temporaryKey;
ms[index].message[i] = ascii;
}
}
void Encrypt()// This function takes in no parameters and encrypts every message in the array of messsages
{
}
void Encrypt::load(string filesname)//Function that loads the file to be encrypted
{
ifstream in;
in.open(filesname.c_str());
if(in.fail()) //if file fails to open do this...
{
cout<<"unable to open file";
}
else//other wise do this
{
while(!in.eof())//while not at the end of the file
{
in >>message[numMessages].key;
in.get();
getline(in.message[numMessages].ms;
numMessages++;
} in.close();
}
}
void print()//This function prints out the message
{
}
void save(string filesname)
{
ostream out;
out<<
}