Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C++ program to Implement the encryption and decryption functions for su

ID: 673614 • Letter: C

Question

Create a C++ program to Implement the encryption and decryption functions for such a scheme that will split the original file into two new files and vice versa. One of these two new files will containt all the characters in the original file in odd position and the other will contain all characters in the even position. For example, if the original file contained the text: Hello World! then the 1st file would contain : HloWrd and the 2nd file would contain: el ol!

1st function:

void split(char sourceFile[ ], char destFile1[ ], char dest File2[ ]);

Function Should:

I. Open sourceFile as an input file stream

II. Open destFile2 and destFile2 as output file streams

III. Read each character from sourceFile

IV. If it's an even numbered character (starting at zero), place it in destFile1

V. Else place it in destFile2

VI. Close the files.

2nd function:

void merge(char sourceFile1[ ], char sourceFile2[ ], char destFile[ ]);

Function Should:

reverse the previous operations

Testing:

I Ask the user for the name of the input file

II. Ask the user for teh names of the two half files

III. Call the split function with the filenames as parameters

IV. Ask the user for the name for the recombined file

V. Call the merge function with the appropriate filenames as parameters

Explanation / Answer

# include <iostream.h>

# include <fstream.h>

# include < conio.h >

Using namespace std;

void split ( char sourceFile [ ], char destFile1 [],char destFile2 []);

void merge (char sourceFile1[ ], char sourceFile2[ ], char destFile [ ] );

void split (char sourceFile [ ], char destFile1 [],char destFile2 [] )

{

int i;

ifstream fin;

fin.open (sourceFile, in);

ofstream fout;

char ch;

for ( i=0;i< sourceFile.length(); i++)

{

sourceFile[i] = fin.get(ch);

if (i%2 ==0)

{

fout.open( destFile1,out);

fout << sourceFile[i];

}

else

{

fout.open (destFile2, out);

fout << sourceFile[i];

}

for (i=0; i< destFile1.length; i++)

{

cout<< destFile1[i];

}

for (i=0;i< destFile2.length; i++)

{

cout << destFile2[i];

}

fout.close();

}

fin.close();

}

}

void merge (char sourceFile1[ ], char sourceFile2[ ], char destFile [ ])

{

int i,j;

ifstream fin1;

ofStream fout1;

fin1.open (destFile1, in);

for (i=0; i<destFile1.length(); i++)

{

sourceFile1[i]= destFile1[i];

}

Fin1.open (destFile2,in);

for (i=0; i<destFile1.length(); i++)

{

sourceFile2[i]= destFile2[i];

}

for (i=0;i< sourceFile1.length(); i++)

{

for (j=0;j< sourceFile2.length(); j++)

{

fout1.open (destFile, out);

fout1 << sourceFile1[i] << sourceFile[j];

}

}

for(i=0;i< destFile.length(); i++);

{

cout << destFile[i];

}

fout1.close();

fin1.close();

}

void main()

{

cout <<”please enter the name of the source File”;

cin >> filename;

cout <<”please enter the name of destination file-1”

cin >>destFile1;

cout <<”please enter the name of destination file-2”

cin >>destFile2;

cout<< “the splitted files are” ;

split(filename, destFile1, destFile2);

cout<< “the merged file is”;

merge (destfile1, destfile2, destfile);

getch(0);

}