Question: I need help with generating RSA encryption code for a C programming ( C 9 0 standard ) for a voting system. It has to

I need help with generating RSA encryption code for a C programming (C90 standard) for a voting system. It has to encrypt the Voters personal details in the RSA format. Below is the C code for the main.c file.
#include
#include
#include
#include
#define MAX_NUMBER_SIZE
#define MAX_FNAME_SIZE 20
#define MAX_LNAME_SIZE 20
#define MAX_MOBNO_SIZE 10
#define MAX_ID_SIZE 10
#define MAX_STNUMBER_SIZE 5
#define MAX_STNAME_SIZE 15
#define MAX_SUBURB_SIZE 20
#define MAX_PCODE_SIZE 4
#define MAX_VOTERS 100
int MAX_PEOPLE =0;
int numVoters =0;
struct dateOfBirth{
unsigned int day;
unsigned int month;
unsigned int year;
};
typedef struct DateOfBirth DoB_t;
struct address{
char streetNumber[MAX_STNUMBER_SIZE];
char streetName[MAX_STNAME_SIZE];
char suburb[MAX_SUBURB_SIZE];
char postCode[MAX_PCODE_SIZE];
};
typedef struct address addr_t;
struct PersonalDetails{
char firstName[MAX_FNAME_SIZE];
char lastName[MAX_LNAME_SIZE];
addr_t address;
char mobileNumber[MAX_MOBNO_SIZE];
DoB_t dateOfBirth;
char shareholderID[MAX_ID_SIZE];
} voters[MAX_VOTERS];
/* COLLECTING VOTES */
void numberOfVoters(); /* Liam */
void getPersonalDetails(); /* Liam */
void encrypt(); /* hansali */
void compress(); /*marcus */
/* RECEIVING VOTES*/
void receiveData(); /* Liam */
void decompress(); /*marcus */
void decrypt(); /* hansali*/
void printResults();
/* MERGE VOTES*/
void mergeVotes();
/************************************************
Linked List Implementation
************************************************/
typedef struct node{
char firstName[MAX_FNAME_SIZE];
char lastName[MAX_LNAME_SIZE];
int numVotes;
struct node * next;
} node_t;
/* Candidate-related functions */
node_t* createNode(char* firstName, char* lastName, int numVotes); /* Harry */
void addCandidate(node_t** head, char* firstName, char* lastName, int numVotes); /* Harry */
void printCandidates(node_t* head); /* Harry */
void vote(node_t* head); /* Harry */
node_t* findCandidate(node_t* head, char* firstName, char* lastName); /* Harry */
node_t* createNode(char* firstName, char* lastName, int numVotes){
node_t* newNode =(node_t*)malloc(sizeof(node_t));
if (newNode == NULL){
fprintf(stderr, "Memory allocation failed
");
exit(EXIT_FAILURE);
}
strcpy(newNode->firstName, firstName);
strcpy(newNode->lastName, lastName);
newNode->numVotes = numVotes;
newNode->next = NULL;
return newNode;
}
void updateVote(node_t* head, int index, char firstName, char lastName){
/* Traverse to find candidate
* If doesn't exist -> make new candidate
*/
node_t* current = head;
/* if new candidate, index is -1*/
if(!(index >=0)){
addCandidate(current, firstName, lastName);
printf("Added new Candidate!
");
return;
}
/* Iterate current to given index and increase vote*/
int counter;
for(counter =0; counter <= index; counter++){
current = current->next;
}
/* found current, increase vote by 1*/
current->numVotes +=1;
printf("Added vote for %s %s
", current->firstName, current->lastName);
}
/* Function to add a candidate to the linked list */
void addCandidate(node_t** head, char* firstName, char* lastName, int numVotes){
node_t* existingCandidate = findCandidate(*head, firstName, lastName);
if (existingCandidate != NULL){
existingCandidate->numVotes++;
printf("Added a vote to existing candidate %s %s
", firstName, lastName);
} else {
if (*head == NULL){
*head = createNode(firstName, lastName, numVotes);
} else {
node_t* current =*head;
while (current->next != NULL){
current = current->next;
}
current->next = createNode(firstName, lastName, numVotes);
}
printf("Added new candidate %s %s with 1 vote
", firstName, lastName);
}
}
/* Function to find a candidate in the linked list */
node_t* findCandidate(node_t* head, char* firstName, char* lastName){
node_t* current = head;
while (current != NULL){
if (strcmp(current->firstName, firstName)==0 && strcmp(current->lastName, lastName)==0){
return current; /* Candidate found */
}
current = current->next;
}
return NULL; /* Candidate not found */
}
/* Function to vote for a candidate */
void vote(node_t* head){
int choice;
printf("
Vote for a candidate (Enter 0 to add a new candidate): ");
scanf("%d", &choice);
if (choice ==0){
char firstName[MAX_NAME_SIZE];
char lastName[MAX_NAME_SIZE];
printf("Enter the first name of the new candidate: ");
scanf("%s", firstName);
printf("Enter the last name of the new candidate:
Please write the correct encryption and decryption codes.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!