Question: #include #include #include #include #define MAX_LINE_LENGTH 1000000 #define DEBUG 0 /* ------------ Project 2 - Problem 3 - Encryption ------------ This file encrypts a text

#include #include #include #include

#define MAX_LINE_LENGTH 1000000 #define DEBUG 0

/* ------------ Project 2 - Problem 3 - Encryption ------------ This file encrypts a text file serially. Most of the work is done for you. Just find what in the program can be parallelized and how to encrypt a character. Don't forget to log the output time of your modified code! */ // ------------------------------------------------------ //

int main (int argc, char *argv[]) { // Catch console errors // Make sure you include the # of threads and your output time file. if (argc != 4) { printf("USE LIKE THIS: encrypt_serial key input_text.txt num_threads output_text.txt time.csv "); return EXIT_FAILURE; }

// Read in the encryption key char* p1; int key = strtol(argv[1], &p1, 10 );

// Open the input, unencrypted text file FILE* inputFile = fopen(argv[2], "r"); // Get num threads int thread_count = strtol(argv[7], NULL, 10);

// Open the output, encrypted text file FILE* outputFile = fopen(argv[4], "w"); FILE* timeFile = fopen(argv[5], "w");

// Allocate and open a buffer to read in the input fseek(inputFile, 0L, SEEK_END); long lSize = ftell(inputFile); rewind(inputFile); unsigned char* buffer = calloc(1, lSize + 1); if (!buffer) fclose(inputFile), fclose(outputFile), // fclose(timeFile), free(buffer), fputs("Memory alloc for inputFile1 failed! ", stderr), exit(1);

// Read the input into the buffer if(1 != fread(buffer, lSize, 1, inputFile)) fclose(inputFile), fclose(outputFile), // fclose(timeFile), free(buffer), fputs("Failed reading into the input buffer! ", stderr), exit(2);

// Allocate a buffer for the encrypted data unsigned char* encrypted_buffer = calloc(1, lSize+1); if (!encrypted_buffer) fclose(inputFile), fclose(outputFile), // fclose(timeFile), free(encrypted_buffer), free(buffer), fputs("Memory alloc for the encrypted buffer failed! ", stderr), exit(3);

// ----> Begin Encryption

// Print to the output file for (int i = 0; i

// Cleanup fclose(inputFile); fclose(outputFile); fclose(timeFile); free(encrypted_buffer); free(buffer);

return 0; } // End main //

/* --------------------------------------------------------------------------------------------------- Sources used: https://stackoverflow.com/questions/3747086/reading-the-whole-text-file-into-a-char-array-in-c */

Please use omp (pragma and its functions) for the parallelization

#include #include #include #include #define MAX_LINE_LENGTH 1000000 #define DEBUG 0 /* ------------

The Cacsar algorithn is an cxample of a block cipher. A block ciphcr is an cncryption algoritho claaacter. Masy pactical algonilums have a laget bock. All block eacrytion algorithas ar embarrassingly parellel, because eacryption of any block can be doae independent of ary oher bicok If we stere each cluaracter iu an 8-bit byte, we Lave 256 different characters. (Some are printable, others are not.) So we can assume that ous alphaber contaius 256 characters. You can use a bey that is borwoen 1 abd 255. Your proerem shoudd 1. Read in a key and the plain text. 2. Dishibude lie plain lexL inucngsi the thresads used alnust equally. 3. Let exch thead encrypt its pontion in parallel. 1. Collates the encrypted text from every threed 5. Sare the encryped text to a tile

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!