Real simple Encryption / Decryption


Author : V.Girish

Environment: Compiled using VC6.0 Sp3 and tested using Win95/98 WinNT4.0 and Win 2000

The following techniques are just the BASICS, i repeat BASICS, which can only be used for fun.
They can be broken by a small child and its not safe at all. I have added it here just for the sake
of letting beginners know what encryption is all about. :-

The Basics :-
	Encryption is the method of scrambling data to something thats unrecognizable normally.
	Decryption is the reverse method of encryption to get back the actual data.

	There have been lots and lots of techniques from the past ages. For example, caesar himself
	used a method by which he would encrypt his messages. The key was something that the end user can 
	use to get back the normal message. If the Key was 3, then all the letters would be shifted 
	forward by 3 to get the encrypted message. To decode it back to normal, the letters have to be shifted 
	back by 3. Assuming that "SAMPLE" was the actual message, S Shifted by 3 would be 1->T, 2->U, 
	3->V. Therefore, S assumes the value "V". The actual message now becomes "VDPSOH" which seems
	to have no meaning at all. By shifting back each character we get the normal message. These days,there
	are a lot more complex algorithms and formulae which manipulate any data that cannot be used without
	knowing the key to decryption.
The Code:-
	Now lets take a look at some simple encryption.

	void Encrypt()
	{
	   char Array[256];		// This can be any value
	   char EncryptedArrar[256];	// The same value as the Array declaration  above

  	   /* Open the file and read it into the array. After that, */ 
	
	   for(int nCnt = 0; nCnt <=256; nCnt++ )
	   {
	     EncryptedArray[nCnt] = Array[nCnt] + 1000; // The value 1000 can be any value you  want to have
  	   }
  	 }


	To decrypt , the reverse has to be done. i.e. subtracting by 1000


	void Decrypt()
	{
	   // Just the reverse of encryption here

	   char Array[256]; 		// This can be any value
	   char DecryptedArrar[256]; 	// The same value as the Array declaration above

 	   /* Open the file and read it into the array. After that, */

	   for(int nCnt = 0; nCnt <=256; nCnt++ )
 	   {
 	     DecryptedArray[nCnt] = Array[nCnt] - 1000;  // This can be any value you want to have
 	   }

 	   // The value of 1000 should be the same for encryption and decryption too
	   // If you use some formula for encryption, use the same for decryption too
	   // If you encrypt using 102030, then subtract 102030 for decryption too

	}

	Here is another really simple technique

	char szTemp[256];
	int nIdx;

	strcpy(szTemp, "some text");
	TRACE("not crypted text %s\n", szTemp);
	
	nIdx = 0;

	while (szTemp[nIdx] != 0)
	{
	  szTemp[nIdx] ^= 21;
	  nIdx++;
	}

	TRACE("crypted text %s\n", szTemp);


WARNING : PLEASE DONT ASSUME THAT THIS IS ENCRYPTION. THIS IS JUST THE SURFACE. IF YOU ARE GOING TO USE 

ENCRYPTION IN A PRACTIAL ENVIRONMENT, I WOULD SUGGEST YOU TO TAKE A LOOK AT Crypto++

OR SUCH SITES WHERE YOU CAN GET BETTER GUIDANCE. ALL LUCK.
Hosted by www.Geocities.ws

1