Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
fstream infile,outfile;
char source[20],dest[20];
void fileopen(fstream &file, char *fn, int mode)
{
file.open(fn,mode);
if(!file)
{
cout<<"file doesnot exit";
getch();
exit(0);
}
}
void readfilename()
{
cout<<"enter the source to perform encrpyt/decrypt the file:";
cin>>source;
fileopen(infile,source,ios::in|ios::binary);
cout<<"enter the destination file to store encrypt/decrypted file:";
cin>>dest;
fileopen(outfile,dest,ios::out|ios::binary);
}

void subecn()
{
char ch;
readfilename();
while(infile)
{
infile.get(ch);
if(infile)
outfile.put(ch+1);
}
}
void subdecr()
{
char ch;
readfilename();
while(infile)
{
infile.get(ch);
if(infile)
outfile.put(ch-1);
}
}
void tranecn()
{
char ch,*buff,*str1,*str2;
int i=0,j=0,k=0;
readfilename();
while(infile)
{
infile.get(ch);
if(infile)
buff[i++]=ch;
}
buff[i]='\0';
str1=(char *)malloc(strlen(buff)/2+1);
str2=(char *)malloc(strlen(buff)/2+1);
for(i=0;i<strlen(buff);i++)>
if(i%2==0)
str1[j++]=buff[i];
else
str2[k++]=buff[i];
str1[j]='\0';
str2[k]='\0';
outfile<<str1<<str2;
}
void trandecr()
{
char ch,*buff,*str1,*str2;
int i=0,j=0,mid;
readfilename();
while(infile)
{
infile.get(ch);
if(infile)
buff[i++]=ch;
}
buff[i]='\0';
cout<<buff;
if(strlen(buff)%2==0)
mid=strlen(buff)/2;
else
mid = strlen(buff)/2+1;
str1=(char *)malloc(mid+1);
str2=(char *)malloc(mid+1);
strncpy(str1,buff,mid);
for(i=mid;i<strlen(buff);i++)>
str2[j++]=buff[i];
str1[mid]='\0';
str2[j]='\0';
for(i=0;i<mid;i++)>
outfile<<str1[i]<<str2[i];
}
int main()
{
int choice;
while(1)
{
cout<<"1 sub encr, 2 sub decr, 3 tran encr 4 tran decr, 5 exit\n";
cin>>choice;
switch(choice)
{
case 1: subecn();
break;
case 2: subdecr();
break;
case 3: tranecn();
break;
case 4: trandecr();
break;
case 5: return 0;
}
infile.close();
outfile.close();
}
}
Posted

1 solution

Not a question at all.

And no (a big no), we're not going to write anything for you. That's is something you need to do.
As I assume, this a homework; it won't entertained here.
If you expect us to do your homework, that's not going to work. There's a pretty good reason behind this: "You won't be learn anything, if you expect others do your work for you".

You can try something on your own at first and when you stuck anywhere, anyone from here would do his/her best to help you out.

Thanks to Richard [^], please read the 6th point from this: A link to the Guidelines
[^]

-KR
 
Share this answer
 
v2
Comments
Richard MacCutchan 16-Oct-15 9:20am    
Very kind of you to refer my post, but the FAQ link at the top of the page is a more comprehensive list.
Krunal Rohit 16-Oct-15 10:01am    
Mmmm, I will add that too.. :)

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900