Encryption decryption program

I need to make a program that reads a file provided ( jumble.txt) and encrypt or decrypt the file.

I have written some code but it won't work.

Please help. I don't know where I was wrong

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

//Function definiton
//Function printHeading
//Input: none
//Processing: Print heading and explanation of programs
//Output: Program Headers and Explanations

// Function Prototype ; Function name is printHeading;
// Function type is void; There is no Function parameters
void printHeading(); //no return parameter


//Function definiton
//Function getInfo
//Input: accepts two string parameters, a single character parameter, an integer parameter.
//Processing: Pass input parameter to the function changeFile
//Output: input parameters


// Function Prototype ; Function name is getInfo;
// Function type is void; Function parameters are two string parameters, a single character parameter, an integer parameter
void getInfo(string,char,int,string);

//Function definiton
//Function changeFile
//Input: accepts two string parameters, a single character parameter, an integer parameter.
//Processing: Open input file for reading, open an output file for writing,
// call encode/decode function and create new character to write to the output file
//Output: outpul file


// Function Prototype ; Function name is changeFile;
// Function type is void; Function parameters are two string parameters, a single character parameter, an integer parameter
void changeFile(string,char,int,string);

//Function definiton
//Function encode
//Input: a single character parameter, an integer parameter (shift number).
//Processing: Add shift number to the character
//Output: single character


// Function Prototype ; Function name is encode;
// Function type is char; Function parameters are a single character parameter, an integer parameter
char encode(char,int);


//Function definiton
//Function decode
//Input: a single character parameter, an integer parameter (shift number).
//Processing: Substract shift number to the character
//Output: single character


// Function Prototype ; Function name is decode;
// Function type is char; Function parameters are a single character parameter, an integer parameter
char decode(char,int);

//Function definiton
//Function printMessage
//Input: none
//Processing: print message to the screen that a new file has been created
//Output: message ( tring)


// Function Prototype ; Function name is printMessage;
// Function type is void; Function parameters are none
void printMessage();

int main()
{
char choice;
string file1, file2;
int shift;

shift=0;
choice='e';

printHeading();

getInfo(file1, choice, shift, file2);
changeFile(file1, choice, shift, file2);
printMessage();
system("pause");
}

//Definition of printHeading function
void printHeading()
{
//Create an output file
ofstream outfile;
outfile.open(file2);

//Print out header
outfile<<"Program to encode and decode files "<<endl<<endl<<endl;

//system("pause");
}

//Definition of getInfo function
void getInfo(string &file1,char &choice,int &shift,string &file2)
{

shift=0;
cout<<"Enter file name that you want to open ";
getline(cin, file1);

cout<<"Encode(E) or Decode (D) ";
cin>>choice;

cout<<"Enter shift number : ";
cin>>shift;

cout<<"Enter file name to write the results ";
getline(cin, file2);
}

//Definition of changeFile function
void changeFile(string file1,char choice,int shift,string file2)
{
char ch1;
ch1='E';

//Open an input file
ifstream infile;
infile.open(file1.c_str());

if (choice=='E'|choice=='e')
encode(ch1,shift);
else if(choice=='D'|choice=='d')
decode(ch1,shift);

//Create an output file
ofstream outfile;
outfile.open(file2);

}

//Definition of encode function
char encode(char ch1,int shift)
{
char a;

while (ch1 != '\n')
a=ch1 + shift;

cout<<"\n";

return a;
}

//Definition of decode function
char decode(char ch1,int shift)
{
char b;

while (ch1 != '\n')
b= ch1 - shift;

cout<<"\n";

return b;
}


//Definition of printMessage function
void printMessage()
{
cout<<endl<<"A new file has been created "<<endl<<endl;

}
Last edited on
Topic archived. No new replies allowed.