You are on page 1of 2

#include<iostream.h> #include<fstream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); fstream f; int n,key,k=0,i,r; char ch,text[50]; f.open("temp.

txt",ios::out ios::in ios::trunc); l: cout<<"\nEnter the choice:\n1.Encryption\n2.Decryption\n"; cin>>n; switch(n) { case 1: { cout<<"\nEnter the key value:\n"; cin>>key; cout<<"Enter data (Press $ to end input):\n"; cin>>text; i=0; while(text[i]!='$') { text[i]+=key; f<<++text[i]; i++; } cout<<"\nThe encrypted data:\n"; k=f.tellp(); i=0; f.seekg(0); while(i<k) { f>>ch; cout<<ch; i++; } break; } case 2: { cout<<"\nThe Decrypted data:\n"; f.seekg(0); i=0; while(i<k) { f>>ch; ch--; cout<<(char)(ch-key); i++; } break; } } cout<<"\nHit 1 to continue:"; cin>>r; if(r==1) goto l;

f.close(); getch(); }

You might also like