Question: Programming in C D esign and implement a tar utility for encrypting and decrypting a single file specified as follows; $ tar2 e file o

Programming in C

Design and implement a tar utility for encrypting and decrypting a single file specified as follows;

$ tar2 e file o file.tar2 (for encrypting)

$ tar2 x file.tar2 (for decrypting)

If the option of encrypting is specified the tar app will ask for a password in order to do that. In order to decrypt an encrypted file the tar app will ask for the password.

Note 1: Do not implement the tar functionality for packing /unpacking a list of files, just the functionality for encrypting and decrypting a single file.

Note 2: For encrypting a file, implement the following algorithm; for each byte in the target file get the module 8 of the ASCII code of each character in the password reading the password from left to right and invert the corresponding bit in the byte. For decrypting a file, for each byte in the tar file get the module 8 of the ASCII code of each character in the password reading the password from right to left and invert the corresponding bit in the encrypted byte.

Files to be delivered: tar2.c

Is this code right for the above problem?

// encrypting and decrypting #include int Encrypt(char * FILENAME, char * NEW_FILENAME) { FILE *inFile; FILE *outFile; char Byte; char newByte; int n; int i=0;

inFile = fopen(FILENAME,"rb"); outFile = fopen(NEW_FILENAME, "w");

if(inFile == NULL || outfile == NULL){ printf("Error in opening file"); return 1; } else { printf(" File Opened, Encrypting"); while(1){ while ( !feof( inFile ) ){ Byte=fgetc(inFile); newByte=Byte+25; fputc(newByte,outFile); } printf("End of File"); break; } fclose(inFile); fclose(outFile); } }

int Decrypt (char *FILENAME, char *NEW_FILENAME) { FILE *inFile; //Declare inFile FILE *outFile; //Declare outFile

char Byte; char newByte; int i=0;

inFile = fopen(FILENAME,"rb"); outFile = fopen(NEW_FILENAME, "w");

if(inFile == NULL || outfile == NULL){ printf("Error in opening file"); return 1; } else { printf("File Opened, Decrypting"); while(1){ printf("."); while ( !feof( inFile ) ){ Byte=fgetc(inFile); newByte=Byte-25; fputc(newByte,outFile); } printf("End of File"); break; } fclose(inFile); fclose(outFile); } }

int main() { char encFile[200]; char newencFile[200]; char decFile[200]; char newdecFile[200]; enFile = "image.jpg"; newenFile = "image.jpg.en"; decFile = "image.jpg.en"; newdecFile = "image.jpg"; Encrypt(encFile, newencFile); Decrypt(decFile, newdecFile); return 0; }

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 Databases Questions!