0% found this document useful (0 votes)
11 views3 pages

Cns Prac1

The document provides a practical implementation of the Caesar cipher for encryption and decryption in C programming. It includes code snippets for both processes, allowing users to input a message and a key to obtain the encrypted or decrypted output. The encryption shifts characters based on the key, while the decryption reverses the process.

Uploaded by

Aesha Patel
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)
11 views3 pages

Cns Prac1

The document provides a practical implementation of the Caesar cipher for encryption and decryption in C programming. It includes code snippets for both processes, allowing users to input a message and a key to obtain the encrypted or decrypted output. The encryption shifts characters based on the key, while the decryption reverses the process.

Uploaded by

Aesha Patel
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/ 3

CNS(3161606) Enroll No:221240116068

Practical-1
AIM: implement Caesar cipher with Encryption/Decryption.
Encryption :
#include <stdio.h>
#include <string.h>
void main() {
int i, key;
char message[100], ch;
printf("Enter the message to encrypt: ");
fgets(message, sizeof(message), stdin);
message[strcspn(message, "\n")] = '\0';
printf("Enter the key: ");
scanf("%d", &key);
key = key % 26;
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\n", message);}

SPCE(IT) 1
CNS(3161606) Enroll No:221240116068

Decrytion :
#include <stdio.h>
#include <string.h>
void main() {
int i, key;
char message[100], ch;
printf("Enter the message: ");
fgets(message, sizeof(message), stdin);
message[strcspn(message, "\n")] = '\0';
printf("Enter the key: ");
scanf("%d", &key);
key = key % 26;
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("Decrypted message: %s\n", message);
}

SPCE(IT) 2
CNS(3161606) Enroll No:221240116068

Output:

SPCE(IT) 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy