A Simple Encryption Alogrithm

Lets Take an Example, you want to send a confidentail message to your cousin over the internet.In other

words, you donot want anyone who might intercept the message to be able to read it.To protect the message you send, you will

encrypt ot encipher the message.


Now Here, i have given out the source code, which implements a similar cryptographic model.



#include <string>

#include <cstdio>

#include <iostream>

#include <fstream>


using namespace std;

char *strencrypt(char *source)
{
char *original=source;

while (*source) {

*source=*source+3;

source++;

}


char *strdecrypt(char *source)
{

char *orginal=source;

while (*source) {

*source = *source -3;
source++;

}

return(orginal);
}


int main()

{

char linein[81],converted[81];
int encryptdecrypt=1;

int i;
ifstream in, inclear;

cout<< "Enter 1 to encrypt , 2 to devrypt: ";

cin>>encryptdecrypt;

if (encryptdecrypt == 1)
in.open("test-enc.txt");


else

in.open("test-dec.txt");

if(!in) {

cout<< "Cannot open File." << endl;
return (1);

}

while (!in.eof()) {
for(i=0;i<80 && !in.eof(); i++)
in.get(linein[i]);

linein[i]=NULL;

if(encryptdecrypt == 1)

strcpy(converted, strencrypt(linein));

else

strcpy(converted, strdecrypt(linein));

cout << converted <<endl;
}

in.close();

cout<<endl<<endl;
if(encryptdecrypt == 1)
inclear.open("test-enc.txt");
else

inclear.open("test-dec.txt")

if(!inclear) {

cout<< "cannot open file." <<endl;

return (1);

}

while (!inclear.eof()) {

for(i=0;i<80 && !inclear.eof(); i++)

inclear.get(linein[i]);

linein[i]=NULL;

cout<<linein<<endl;

}

inclear.close();

return 0;
}
This is an simple encryption algorithm, i have laid out here for some new comers to encryption.

If you any doubts you can post the question down here, i will be very happy to answers your questions/


Inturn If this Code has helped you in any manner, It would very kind, in turn to visit my small community for Programmers

Developers and Designers/

http://www.httpguru.com

Regards

Biju