Hello everyone,
I am trying to write a program that gives you 3 options:
1 for encryption
2 for decryption
3 Exits the program
If option 1, my program will ask for a password, an input file name and an output file name. My program will then read the file and mesh it with the password resulting in an encrypted file. It will write this file out.
If option 2, my program will ask for the password and the encrypted file name. Read the file and perform a decryption, printing the decryption on the screen
If option 3, the program will stop.
This is what I have so far:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
void do_again(),direction(int ans);
void option_1(),option_2(),option_3();
int main()
{
do_again();//calls do_again function
return 0;
}//end function
void do_again()
{
int ans;//this will be used every time
do
{ //User menu
cout << "Hello and welcome.\n\n";
cout << "Please choose one of the following.\n";
cout << "1: Encryption\n";
cout << "2: Decryption\n";
cout << "3: Exit\n";
cin >> ans;
cin.ignore(80,'\n'); //this reads what the user chose
direction(ans);//sends the answer to direction
}while(ans!=3);//program keeps going until the user chooses exit
}//end of this function
void direction(int ans)
{
switch (ans)//Go through the options
{
case 1:
option_1();
break;
case 2:
option_2();
break;
case 3:
option_3();
break;
default://If anything other than 1,2,3 is chosen
cout << "The option you have chosen was not listed, please try again.\n";
break;
}
}//end of case functions
void option_1() //If option 1 is choosen, encryption begins
{
char a[5000];
char pw[15];
char buffer[256];
int x,y;
int i,j;
int choice=4;
ifstream examplefile ("c:\\proj3cpp.txt");
if (! examplefile.is_open())
{
cout << "Error opening file";
exit (1);
}
while (! examplefile.eof() )
{
examplefile.getline (buffer,100);
cout << buffer << endl;
}
cout<<endl<<"Please enter a password: "; //User inputs a password
cin>>pw;
x=strlen(a);
y=strlen(pw);
j=0;
for (i=0; i<x; i++)
{
if (j>=y) j=0;
a[i]=a[i]+pw[j];
}
cout<<endl<<a;
cout<<endl<<"Encryption is now complete and has been saved to a text document.\n\n";
}
void option_2()// If option 2 is chosen, decryption begins
{
}
void option_3()// If option 3 is chosen, program closes.
{
}
My problems are:
- how do I get it to actually encrypt the text file I have and save the encrypted text to a new text file?
-Is there a way to make the text file =a so it goes through the encryption process?
-How can I make it so it asks the user for a file name?
Thanks in advance!