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

Cipher.: Program 1: Write A Program To Implement Ceaser

The document describes a program to implement a Caesar cipher. The program allows the user to choose to encrypt or decrypt a text by entering 'e' or 'd', respectively. It then prompts the user to enter the text and a key. For encryption, it shifts each character by the key and prints the encrypted text. For decryption, it shifts each character in the opposite direction of the key and prints the decrypted text. The program loops until the user enters a character other than 'e' or 'd'.

Uploaded by

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

Cipher.: Program 1: Write A Program To Implement Ceaser

The document describes a program to implement a Caesar cipher. The program allows the user to choose to encrypt or decrypt a text by entering 'e' or 'd', respectively. It then prompts the user to enter the text and a key. For encryption, it shifts each character by the key and prints the encrypted text. For decryption, it shifts each character in the opposite direction of the key and prints the decrypted text. The program loops until the user enters a character other than 'e' or 'd'.

Uploaded by

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

PROGRAM 1: WRITE A PROGRAM TO IMPLEMENT CEASER

CIPHER.

#include <stdio.h>
int main()
{
char ch, x;
char text[100];
int i, key, flag=0;
do{
printf("To encrypt, input e or E\n\n");
printf("To decrypt, input d or D\n\n");
printf("To exit, input any other letter\n\n");
printf("Your choice ->");
scanf("%c", &ch);
if(ch == 'e' || ch == 'E'){
printf("Input text to encrypt -> ");
scanf("%s", text);
printf("Enter key: ");
scanf("%d", &key);
for(i=0; text[i]!='\0'; i++){
x = text[i];
x = text[i] -32 + key;
if(x>90){
x -= 26;
}
text[i] = x;
printf("%c", text[i]);
}
printf("\n");
}

AKSHAT JAIN 1703013008


else if(ch == 'd' || ch == 'D'){
printf("Input text to decrypt -> "
scanf("%s", text);
printf("Enter key: ");
scanf("%d", &key);
for(i=0; text[i]!='\0'; i++){
x = text[i];
x = text[i] + 32 - key;
if(x<95){
x += 26;
}

OUTPUTS:

AKSHAT JAIN 1703013008


AKSHAT JAIN 1703013008

You might also like