Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;

}

image text in transcribed
[ xwei@scln1 ~]$ nano P6. C [ xwei@scln1 ~]$ gcc -Wall P6. c [ xwei@scln1 ~]$ ./try_date_encrypt Enter the file name: Enter date in the format of 6 digit: Output file name: inpu t message . txt . ecp J igbzm sbfjw bubvjww boppcwdff upnz xkmt jxf i bz hamn ditdcb ujelmct uq upn gittb ixgoby gjxf xnpqnf eqp demt ro. Jv twdoeu njmf ndo. Mgua jmm ebtu bof hw cphgupns. Expected: Enter file name: input_message . txt Enter the date in the format of 6 digit: 112189 igbzm sbfjw bubvjww boppcwdff upnz xkmt hixf ifbz hsmn ditdcb ujelmet uq upn gittb uxgobh gjxf xnpqnf eqp demt ro. Jv twdoeu njmf ndo. Mgua jmm ebtu bof hw cphgupns. Enter the file name: Enter date in the format of 6 digit: Output file name: inpu [ message2 . txt . ecp Nix dnmnx xist mifw jwu Qpqkiy rjjob ax olum. Avslcm ax bujidi xhhzirh d ymd xjh. Slf zptl etn wu jpu ape gpuymcx ultm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions