using namespace std;
void Encryption()
{
cout << "\nWhat is the location of the file you would like to encrypt?" << endl;
string fileloc;
getline (cin, fileloc); //cin gets the file location as a string
cin >> fileloc;
infile.open (fileloc.c_str()); //opens the file to be encrypted
infile2.close();
cout << "\nWhat is the password you would like to use to create the encryption?" << endl;
cout << "\nPlease enter a four letter word." << endl;
string password;
getline (cin,password); //cin gets the meshing password as a string
cin >> password;
cout << "\n\nWhat is the name of the file to which you would like to print the encryption?" << endl;
string outfileloc;
getline (cin, outfileloc); //cin gets the output file as a string
cin >> outfileloc;
outfile.open (outfileloc.c_str()); //opens the output file
while (!infile.eof()) //while not the end of the file
{
for (int i=0 ;i<4 ; i++) //for loop cycles through the positions of the password array until end of file is reached
{
char name; //character from file to be encrypted
infile.get(name); //gets character from the file
name = name + password[i]; //adds the part of the password array
name = name - password[0]; //subtracts the first letter of the password (keeps characters printable)
outfile << name; //prints that character to the output file
}
}
infile.close(); //closes the original file
outfile.close(); //closes the file encryption
cout << "\n\n"; //aesthetic purposes
}
void Decryption()
{
cout << "\nWhat is the location of the file you would like to decrypt?" << endl;
string fileloc;
getline (cin, fileloc); //cin gets the location of the file to be decrypted as a string
cin >> fileloc;
infile2.open (fileloc.c_str()); //opens the file using infile2 (different input file)
cout << "\nWhat is the password used when the text was encrypted?" << endl;
cout << "\nPlease enter the four letter word." << endl;
string password;
getline (cin,password); //gets password used for encrypting as a string
cin >> password;
cout << "\n\n";
while (!infile2.eof()) //while not the end of the file
{
for (int i=0 ;i<4 ; i++) //for loop cycles through the positions of the password array until end of file is reached
{
char name; //character from file to be decrypted
infile2.get(name); //gets character from file
name = name + password[0]; //re-adds the first letter of the password
name = name - password[i]; //subtracts the proper letter from the password array
cout << name; //prints decrypted character to screen
}
}
infile2.close(); //closes file that was being decrypted
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
usingnamespace std;
void Encryption()
{
cout << "\nWhat is the location of the file you would like to encrypt?" << endl;
string fileloc;
getline (cin, fileloc); //cin gets the file location as a string
cin >> fileloc;
infile.open (fileloc.c_str()); //opens the file to be encrypted
infile2.close();
cout << "\nWhat is the password you would like to use to create the encryption?" << endl;
cout << "\nPlease enter a four letter word." << endl;
string password;
getline (cin,password); //cin gets the meshing password as a string
cin >> password;
cout << "\n\nWhat is the name of the file to which you would like to print the encryption?"<< endl;
string outfileloc;
getline (cin, outfileloc); //cin gets the output file as a string
cin >> outfileloc;
outfile.open (outfileloc.c_str()); //opens the output file
while (!infile.eof()) //while not the end of the file
{
for (int i=0 ;i<4 ; i++) //for loop cycles through the positions of the password array until end of file is reached
{
char name; //character from file to be encrypted
infile.get(name); //gets character from the file
name = name + password[i]; //adds the part of the password array
name = name - password[0]; //subtracts the first letter of the password (keeps characters printable)
outfile << name; //prints that character to the output file
}
}
infile.close(); //closes the original file
outfile.close(); //closes the file encryption
cout << "\n\n"; //aesthetic purposes
}
void Decryption()
{
cout << "\nWhat is the location of the file you would like to decrypt?" << endl;
string fileloc;
getline (cin, fileloc); //cin gets the location of the file to be decrypted as a string
cin >> fileloc;
infile2.open (fileloc.c_str()); //opens the file using infile2 (different input file)
cout << "\nWhat is the password used when the text was encrypted?" << endl;
cout << "\nPlease enter the four letter word." << endl;
string password;
getline (cin,password); //gets password used for encrypting as a string
cin >> password;
cout << "\n\n";
while (!infile2.eof()) //while not the end of the file
{
for (int i=0 ;i<4 ; i++) //for loop cycles through the positions of the password array until end of file is reached
{
char name; //character from file to be decrypted
infile2.get(name); //gets character from file
name = name + password[0]; //re-adds the first letter of the password
name = name - password[i]; //subtracts the proper letter from the password array
cout << name; //prints decrypted character to screen
}
}
infile2.close(); //closes file that was being decrypted
cout << "\n\n"; //aesthetic purposes
return 0;
}
2nd: Does your compiler return any errors? It helps to read through them....
infile, outfile, and infile2 aren't defined anywhere
Decryption() is of type void yet it returns 0