Encryption and Decryption
Encryption and Decryption
Date :
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.
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);
message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + key;
message[i] = ch;
}
}
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;
9
for(i = 0; message[i] != '\0'; ++i){
ch = message[i];
message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - key;
message[i] = ch;
}
}
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