logo

Foundations of Cyber Security

26 Pages5206 Words328 Views
   

Added on  2023-04-21

About This Document

This document provides an implementation of the Vigenere cipher in a C program. It explains the process of encrypting and decrypting a message using the cipher and discusses the robustness and vulnerabilities of the cipher. The document also provides recommendations for using the cipher.

Foundations of Cyber Security

   Added on 2023-04-21

ShareRelated Documents
FOUNDATIONS OF CYBER SECURITY
Combined Coursework
Module: CTEC5801
Foundations of Cyber Security_1
Question 1: Implementing the Vigenere cipher in a C program.
Below is the implementation of the cipher in C.
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <process.h>
//functions to be used in the program
void cipher(char *,char *);
void encrypt();
void decrypt();
main()
{
int choose;
//User’s choice taken and the necessary function called.
while(1)
{
printf("Enter 1 to encrypt the Text\n");
Foundations of Cyber Security_2
printf("Enter 2 to decrypt the Text\n");
printf("Enter 3 to exit\n");
printf("Choose one of the above :\n ");
scanf("%d",&choose); //stores the choice
fflush(stdin);//clears the screen
if(choose == 3) //selection statement
exit(0);
else if(choose == 1)
encrypt(); //calls the encryption function when the conditions
are met.
else if(choice == 2)
decrypt(); //calls the decrypt function
else
printf("Invalid choice\n");
}
return 0;
}
Foundations of Cyber Security_3
void encrypt() //contents of the encrypt function
{
int a;
int b; //variable declaration
char EnteredText[100];
char keyword[27];
printf("Please input the text you want to encrypt :\n ");
gets(input);
printf("Please Enter the Encryption keyword:\n ");
gets(keyword);
for(a=0,b=0;a<strlen(EnteredText);a++,b++)
{
//The key is repeated when the end is reached.
if(b>=strlen(keyword))
{
b=0;
Foundations of Cyber Security_4
}
//Encryption happens by adding character from the text to the
character from the key%26
printf("%c",65+(((toupper(EnteredText[a])-65)+(toupper(keyword[b])-
65))%26));
}
}//
void decrypt()// decryption function
{
int a,b;
char EnteredText[100];
char keyword[26];
int output;//stores the value.
printf("Which text do you want to decrypt? :\n ");
gets(EnteredText);
printf("Enter Decryption Key :\n ");
gets(keyword);
Foundations of Cyber Security_5
for(a=0,b=0;a<strlen(EnteredText);a++,b++)
{
//This loop is for repeating the keyword when the end is reached.
if(b>=strlen(keyworld))//selection statement
{
j=0;
}
//This is the same as decrypting, only that this time it is
subtraction
output = (toupper(EnteredText[a])-64)-(toupper(key[b])-64);
//Rotate the value backwards if negative and add it to 26
if( output < 0)//selection statement
{
output = 26 + value;
}
Foundations of Cyber Security_6

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Foundation of Cyber Security
|23
|5334
|304

Questions on Stack Program
|11
|1305
|31

Desklib - Online Library for Study Material
|11
|2075
|276

Hostel Management System
|25
|1266
|447

Programming in C and C++
|11
|1850
|78

NIM Game Playing Interface in Java
|8
|2250
|180