Sat Jan 26, 2013 8:48 pm
#include<iostream>//for cin , cout.
using namespace std;
#include<iomanip>// for setw().
#include<windows.h>//for set_color(); ,clear_screen();.
#include<conio.h>//for getche().
int main()// main function.
{
char enc[2000];//the string for the text.
int count,i,j;//for loop counter.
char choise,cho='y';//do while variable.
char temp;
do
{
cout<<setw(40)<<"Enter the text which you want to encrypt: \n\n\t";
if(cin.peek() == '\n')
cin.get(); // add this line
cin.get(enc, 2000);
cout<<setw(20)<<"(e) to encrypt .\n(d) to decrypt .\n(x) to exit.\n\a ";
cin>>choise;
if(choise=='e'||choise=='E')
{
for(i=0,j=strlen(enc)-1;i<strlen(enc)/2;i++,j--)
{
temp=enc[j];
enc[j]=enc[i];
enc[i]=temp;
}
for(count=0;count<strlen(enc);count++)
{
if(enc[count]+count>255)
enc[count]=enc[count]-255+count;
else
enc[count]+=count;
}
cout << "Encrypted Text is: " << enc << endl;
}
else if(choise=='x'||choise=='X')
return 0;
else if(choise=='d'||choise=='D')
{
for(count=1;count<strlen(enc);count++)
{
if(enc[count]-count<0)
enc[count]=enc[count]+(255-count);
else
enc[count]-=count;
}
for(i=0,j=strlen(enc)-1;i<strlen(enc)/2;i++,j--)
{
temp=enc[i];
enc[i]=enc[j];
enc[j]=temp;
}
cout<<enc<<endl;
}
else
{
cout<<"please ,enter :\n(e) to encrypt .\n(d) to decrypt .\n(x) to exit.\n ";
}
cout<<"Do you want to continue?(y/n) ";
cin>>cho;
}while((cho=='y')||(cho=='Y'));
return 0;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.