0% found this document useful (0 votes)
17 views

Encryption and Decryption

Uploaded by

Yogesh Yogu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Encryption and Decryption

Uploaded by

Yogesh Yogu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise : 3 Implementation of Encryption and Decryption

Date :

Aim : To study and implement the process of Encryption and Decryption


.
Components Required : PC with TURBO C

Principle:
CRYPTOGRAPHY (secret writing) is the process which uses the encryption and
decryption algorithm. An encryption algorithm transforms the plain-text into cipher text
(unknown format) and decryption algorithm transforms the cipher text back into plain-
text. The sender uses an encryption algorithm to send the information in the unknown
format and the receiver uses a decryption algorithm to retrieve the original information.

Caesar Cipher is one of the simplest encryption technique in which each character in
plain text is replaced by a character some fixed number of positions down to it.
For example, if the key is 3 then we have to replace character by another character that
is 3 position down to it. Like A will be replaced by D, C will be replaced by F and so on.
For decryption just follow the reverse of encryption process.

Program for Caesar Cipher in C

Encryption

#iinclude<stdio.h>
int main()
{
char message[100], ch;
int i, key;
printf("Enter a message to encrypt: ");
gets(message);
printf("Enter key: ");
8
scanf("%d", &key);

for(i = 0; message[i] != '\0'; ++i){


ch = message[i];
if(ch >= 'a' && ch <= 'z'){
ch = ch + key;
if(ch > 'z'){
ch = ch - 'z' + 'a' - 1;
}

message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + key;

if(ch > 'Z'){


ch = ch - 'Z' + 'A' - 1;
}

message[i] = ch;
}
}

printf("Encrypted message: %s", message);

return 0;
}

Sample Output
Enter a message to encrypt: axzd
Enter key: 4
Encrypted message: ebdh

#include<stdio.h>

int main()
{
char message[100], ch;
int i, key;

printf("Enter a message to decrypt: ");


gets(message);
printf("Enter key: ");
scanf("%d", &key);

9
for(i = 0; message[i] != '\0'; ++i){
ch = message[i];

if(ch >= 'a' && ch <= 'z'){


ch = ch - key;

if(ch < 'a'){


ch = ch + 'z' - 'a' + 1;
}

message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - key;

if(ch < 'A'){


ch = ch + 'Z' - 'A' + 1;
}

message[i] = ch;
}
}

printf("Decrypted message: %s", message);

return 0;
}

Sample Output :
Enter a message to decrypt: ebdh
Enter key: 4
Decrypted message: axzd

RESULT :
Thus the program for encryption and decryption using Caesar Cipher in C is studied and
implemented.

10

You might also like