0% found this document useful (0 votes)
54 views5 pages

Caesar Cipher C Program Guide

The document describes implementing a Caesar cipher for encryption and decryption in C programming. It includes the source code for both encryption and decryption algorithms. The encryption code shifts each character by a key value, wrapping around the alphabet. The decryption code performs the inverse shift to recover the original text. Sample outputs are provided for testing the encryption and decryption processes.

Uploaded by

Ridham Vyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views5 pages

Caesar Cipher C Program Guide

The document describes implementing a Caesar cipher for encryption and decryption in C programming. It includes the source code for both encryption and decryption algorithms. The encryption code shifts each character by a key value, wrapping around the alphabet. The decryption code performs the inverse shift to recover the original text. Sample outputs are provided for testing the encryption and decryption processes.

Uploaded by

Ridham Vyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Practicle:1

AIM:- Implement Caesar cipher encryption-decryption

Source code:-C programming


 Encryption

#include<stdio.h>

#include<conio.h>

int main()

int i, key;

char text[100],c;

printf("\nC Program to Perform Caesar Cipher (Decryption)");

printf("\nEnter Message : ");

gets(text);

printf("\nEnter Key : ");

scanf("%d", &key);

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

c = text[i];

if(c >= 'a' && c <= 'z')

c = c - key;

if(c < 'a')

{
c = c + 'z' - 'a' + 1;\

text[i] = c;

else if(c >= 'A' && c <= 'Z')

c = c - key;

if(c < 'A')

c = c + 'Z' - 'A' + 1;

text[i] = c;

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

getch();

 Output:-
 Decryption

#include<stdio.h>

#include<conio.h>

int main()

int i, key;

char text[100],c;

printf("\nC Program to Perform Caesar Cipher (Decryption)");

printf("\nEnter Message : ");

gets(text);

printf("\nEnter Key : ");

scanf("%d", &key);

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

c = text[i];

if(c >= 'a' && c <= 'z')


{

c = c - key;

if(c < 'a')

c = c + 'z' - 'a' + 1;

text[i] = c;

else if(c >= 'A' && c <= 'Z')

c = c - key;

if(c < 'A')

c = c + 'Z' - 'A' + 1;

text[i] = c;

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

getch();

}
 Output:-

You might also like