Switch to full style
C++ code examples
Post a reply

encryption/ decryption without key using C++

Sat Jan 26, 2013 8:48 pm

encryption/ decryption without key using C++
cpp code
#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;
}




Post a reply
  Related Posts  to : encryption/ decryption without key using C++
 Encryption and Decryption encryption Affine cipher code     -  
 encryption and decryption in c++     -  
 codes for encryption/decryption algorithms     -  
 Row Transposition cipher - encryption-decryption Csharp(C#)     -  
 Row Transposition cipher - encryption-decryption java     -  
 RSA encryption decryption cipher algorithm java     -  
 Ceasar encryption-decryption-cipher-decipher code     -  
 Encryption Algorithm{Data Encryption Standard}     -  
 Encryption decoding     -  
 video encryption     -  

Topic Tags

C++ Algorithms