Question
My code appears strange and garbled. There may be a problem with initialization. How can I modify it? #include #include //encrypt method void encrypt(char *message,
My code appears strange and garbled. There may be a problem with initialization. How can I modify it?
#include
#include
//encrypt method
void encrypt(char *message, int date[], int n)
{
int i = 0, j = 0;
//Using while function to ignore the empty spaces
while(message[i] != '\0')
{
char ch = message[i];
//From A to Z
if(ch >= 65 && ch
{
ch = ch + date[j];
//Wraping-around if there is an overflow
if(ch > 90)
ch = ch % 90 + 64;
j++;
}
//From a to z
if(ch >= 97 && ch
{
ch = ch + date[j];
//Wraping-around if there is an overflow
if(ch > 122)
ch = ch % 122 + 96;
j++;
}
j = j % n;
message[i] = ch;
i++;
}
}
int main()
{
char input_file[100], message[10000], input_date[6];
int date[6], i;
//Setting up File variables
FILE *fp, *fpout;
printf("Enter the file name: ");
scanf("%s", input_file);
//Error for file doesn't exist
if ((fp = fopen(input_file, "r")) == NULL)
{
printf("Error! File Not Found ");
return 0;
}
printf("Enter date in the format of 6 digit: ");
scanf("%s", input_date);
for(i = 0; i
date[i] = input_date[i] - 48;
//Creating and open the encrypt file
fpout = fopen(strcat(input_file, ".ecp"), "w+");
if(fpout == NULL)
{
printf("Error! Unable to create file ");
return 0;
}
//Reads each line of the file and store them in message variable
while(fgets(message, sizeof(message), fp) != NULL)
{
//Calling encrypt method
encrypt(message, date, 6);
//Writes encrypted message in the new file
fprintf(fpout, "%s", message);
}
printf("Output file name: %s ", input_file);
//Close files
fclose(fp);
fclose(fpout);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started