1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include "conio.h"
using namespace std;
void encrypt();
void option(int opt);
void EncryptOption();
void DecryptOption();
void EXIT();
int main()
{
encrypt();
return 0;
}
void encrypt()
{
int opt;
do
{
cout << "WELCOME TO THE ENCRYPTOR!!.\n\n";
cout << "Please choose one of the following...\n";
cout << "1: Encryption\n";
cout << "2: Decryption\n";
cout << "3: Exit\n";
cin >> opt;
cin.ignore(80,'\n'); //this reads what the user chose
option(opt);//sends the answer to option
}while(opt!=3);//program keeps going until the user chooses exit
}//end of this function
void option(int opt)
{
switch (opt)//Go through the options
{
case 1:
EncryptOption();
break;
case 2:
DecryptOption();
break;
case 3:
EXIT();
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 EncryptOption() //If option 1 is choosen, encryption begins
{ //declare variables//
char Pass[40], name[40];
int a,b,x,y;
const char* filename="Plaintext.txt"; //name of file
ifstream infile(filename);
//prompt for password//
cout<<"Please enter your Key:\n";
cin>>Pass;
x=strlen(name);
y=strlen(Pass);
ofstream outfile;
outfile.open("encrypt.txt",ios::ate);
for(a=0,b=0; a<x; a++,b++)
{
if (b>=y)
b=0;
name[a]=name[a]+Pass[b];
}
outfile<<endl<<name;
cout<<endl;
outfile.close();
cout<<"Encryption is finished!\n";
exit (0);
}
void DecryptOption()// If option 2 is chosen, decryption begins
{
//declare variables//
char Pass[40], name[40];
int a,b,x,y;
const char* filename="encrypt.txt"; //name of file
ifstream infile(filename);
//prompt for password//
cout<<"Please enter your Key:\n";
cin>>Pass;
x=strlen(name);
y=strlen(Pass);
for(a=0,b=0; a<x; a++,b++){
if (b>=y)
b=0;
name[a]=name[a]-Pass[b];
}
cout<<endl<<name;
cout<<endl;
cout<<"Decryption is finished!\n";
exit (0);
}
void EXIT()// If option 3 is chosen, program closes.
{
}
| |