EXPERIMENT 2. Encryption Decryption
EXPERIMENT 2. Encryption Decryption
Experiment No:02
Theory:
Example
An employer wants to send some sensitive documents to an employee for processing
but can’t risk hackers getting hold of the documents and reading them. The
employer can encrypt the documents and then send them to the employee who can
then decrypt the documents using an employer-provided encryption key. They can
then start working on the documents as they would normally.
More specifically, let’s say a document contains a top-secret word like “ALUMINUM.”
This word could be encrypted with an algorithm that replaces each letter with the
letter that follows it in the alphabet.
So, the “A” in ALUMINUM would become “B,” the “L” would become “M” and so on to
give a cipher “BMVNJOVN.” Anyone who wants to know what the original message
was must know the algorithm which was used to encrypt the original information.
This is a very simple example so one can easily tell what the original message was.
In the real world, far more complicated algorithms are used to encrypt information.
In any case, the sending party would let the receiving party know the encryption key.
In this case, the key is to replace each letter with the letter that follows it in the
alphabet. Using this key, the receiving party would decrypt the message, read the
contents and move on.
int main()
{
int i, x;
char str[100];
printf("\nPlease enter a string : ");
gets(str);
printf("\nPlease Enter your choice : \n");
printf("1. Encryption\n");
printf("2. Decryption\n");
scanf("%d", &x);
//using switch case statements
switch(x)
{
case 1:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value
printf("\nEncrypted string is : %s\n", str);
break;
case 2:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value
printf("\nDecrypted string is : %s\n", str);
break;
default:
printf("\nError : Please Enter correct choice \n");
}
return 0;
}
OUTPUT :
Conclusion:
Therefore, I have understood and studied the concept of encryption and decryption
and also analysed its functioning using a C++ Code.