0% found this document useful (0 votes)
43 views4 pages

Lab 1

The document describes a C program that implements the Caesar cipher encryption algorithm. The program takes a plain text message and encryption key from the user. It initializes arrays to hold the alphabet and encrypted text. The program iterates through each character, finds its position in the alphabet array, shifts it by the key, and saves the encrypted character in the output array. Finally, it prints the encrypted text. The program successfully encrypts input plain text using the Caesar cipher approach.

Uploaded by

Denis Priscus
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)
43 views4 pages

Lab 1

The document describes a C program that implements the Caesar cipher encryption algorithm. The program takes a plain text message and encryption key from the user. It initializes arrays to hold the alphabet and encrypted text. The program iterates through each character, finds its position in the alphabet array, shifts it by the key, and saves the encrypted character in the output array. Finally, it prints the encrypted text. The program successfully encrypts input plain text using the Caesar cipher approach.

Uploaded by

Denis Priscus
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/ 4

ARUSHA TECHNICAL COLLEGE

DEPARTMENT: INFORMATION COMMUNICATION TECHNOLOGY


PROGRAM: COMPUTER SCIENCE
NAME: DONALD DONALD MWAKATOGA
ADMISSION: 21050513023
Objective:
Demonstrating the Caesar cipher's implementation in C.
Programing language used:
C programing language
Methodology used to implement Caesar Cipher encryption using C language
The Caesar Cipher encryption algorithm is implemented in this C code, which requests a
plain text message from the user along with an alphabet shift key. An array is initialized to
hold the alphabet, and another is initialized to hold the encrypted text. The program searches
the alphabet array for matches as iteratively goes over each character in the user-provided
plain text. It uses the key to determine the encrypted character's index for each match, then
saves the result in the encrypted text array. With the assumption that the input consists solely
of lowercase letters, the software outputs the encrypted text that results.

//Header files for standard input and output header files


#include <stdio.h>
#include <stdlib.h>

//Main function, entry point of every C program


int main(int argc, char *argv[]) {
//created a variable which is an array of type char to store plain text entered by a user
char plain_text[30];
//Prompting user to write the plain text to encreapt
printf("Please give us plain text to increapt: \t");
//accepting the plain text input from the user and store it in plain text variable
scanf("%s",&plain_text);
//Prompting user to tell use wants to encrypt the text using what key
printf("Please give us the key for the cypher: \t");
//Creating a variable key to store value from user
int key;
//Accepting input from user and store them in variable key
scanf("%d",&key);
//Created an alphabet variable array of type char to store the list of characters
char alphabets[] =
{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//Created cyphered text variable with size of 100 for storing encrypted text
char cypher_text[100];
//Initialized index variable for tracking the index of cyphered text when encrypting
int index = 0;

int i,j,cyphered_char_index;
//Looping through from 0 to size of plain text
for(i = 0; i < sizeof(plain_text); i++){
//Looping from 0 to size of alphabets list
for(j = 0; j < sizeof(alphabets); j++){
//Comparing plain text char of index i with alphabet of index j if true
if(plain_text[i] == alphabets[j]){
//If condition is true perform operation to encrypt the character
cyphered_char_index = ((j+key)%26);
//update cypher text at particular index to a cyphered char
cypher_text[index] = alphabets[cyphered_char_index];
//update index value to plus one
index++;
}
}
}
//Output the cyphered text here
printf("%s",cypher_text);
}
Results:
The application uses the Caesar Cipher and input cryptographic key to encrypt the plain text
and successfully encrypted.

You might also like