Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a file encrypted using Pseudo-random number generator: https://drive.goog

ID: 3736657 • Letter: I

Question

I have a file encrypted using Pseudo-random number generator: https://drive.google.com/open?id=1gZCujDYmEL-FZ5o_xBUS-Ng5979HSsZ7, and I know the plaintext probably starting with “documentclass[12pt]{article}” The code used for encryption was written in C, and it is required to decrypt the file
/* The ISO/IEC 9899:1990 edition of the C standard */ #define RAND_MAX 32767 static unsigned long int next = 1; int rand(void) // RAND_MAX assumed to be 32767 { next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } void srand(unsigned int seed) { next = seed; } #include <stdio.h> #include <time.h> //Return a byte at a time of the rand() keystream char randchar() { static int key; static int i = 0; i = i % 4; if (i == 0) key = rand(); return ((char *)(&key))[i++]; } int main(int argc, const char* argv[]) { static char randstate[64]; srand(time(NULL)); FILE *input, *output; input = fopen("Homework1b.tex", "r"); output = fopen("Homework1b.tex.enc", "w"); int c,rc; while ((c = fgetc(input)) != EOF) { rc=randchar(); printf("c=%d (%c) and rc=%d ",c,c,rc); fputc(c^rc,output); } fclose(input); fclose(output); } I have a file encrypted using Pseudo-random number generator: https://drive.google.com/open?id=1gZCujDYmEL-FZ5o_xBUS-Ng5979HSsZ7, and I know the plaintext probably starting with “documentclass[12pt]{article}” The code used for encryption was written in C, and it is required to decrypt the file
/* The ISO/IEC 9899:1990 edition of the C standard */ #define RAND_MAX 32767 static unsigned long int next = 1; int rand(void) // RAND_MAX assumed to be 32767 { next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } void srand(unsigned int seed) { next = seed; } #include <stdio.h> #include <time.h> //Return a byte at a time of the rand() keystream char randchar() { static int key; static int i = 0; i = i % 4; if (i == 0) key = rand(); return ((char *)(&key))[i++]; } int main(int argc, const char* argv[]) { static char randstate[64]; srand(time(NULL)); FILE *input, *output; input = fopen("Homework1b.tex", "r"); output = fopen("Homework1b.tex.enc", "w"); int c,rc; while ((c = fgetc(input)) != EOF) { rc=randchar(); printf("c=%d (%c) and rc=%d ",c,c,rc); fputc(c^rc,output); } fclose(input); fclose(output); } The code used for encryption was written in C, and it is required to decrypt the file
/* The ISO/IEC 9899:1990 edition of the C standard */ #define RAND_MAX 32767 static unsigned long int next = 1; int rand(void) // RAND_MAX assumed to be 32767 { next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } void srand(unsigned int seed) { next = seed; } #include <stdio.h> #include <time.h> //Return a byte at a time of the rand() keystream char randchar() { static int key; static int i = 0; i = i % 4; if (i == 0) key = rand(); return ((char *)(&key))[i++]; } int main(int argc, const char* argv[]) { static char randstate[64]; srand(time(NULL)); FILE *input, *output; input = fopen("Homework1b.tex", "r"); output = fopen("Homework1b.tex.enc", "w"); int c,rc; while ((c = fgetc(input)) != EOF) { rc=randchar(); printf("c=%d (%c) and rc=%d ",c,c,rc); fputc(c^rc,output); } fclose(input); fclose(output); } /* The ISO/IEC 9899:1990 edition of the C standard */ #define RAND_MAX 32767 static unsigned long int next = 1; int rand(void) // RAND_MAX assumed to be 32767 { next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } void srand(unsigned int seed) { next = seed; } #include <stdio.h> #include <time.h> //Return a byte at a time of the rand() keystream char randchar() { static int key; static int i = 0; i = i % 4; if (i == 0) key = rand(); return ((char *)(&key))[i++]; } int main(int argc, const char* argv[]) { static char randstate[64]; srand(time(NULL)); FILE *input, *output; input = fopen("Homework1b.tex", "r"); output = fopen("Homework1b.tex.enc", "w"); int c,rc; while ((c = fgetc(input)) != EOF) { rc=randchar(); printf("c=%d (%c) and rc=%d ",c,c,rc); fputc(c^rc,output); } fclose(input); fclose(output); }

Explanation / Answer

#define RAND_MAX 32767

static unsigned long int next = 1;

int rand(void) // RAND_MAX assumed to be 32767

{

next = next * 1103515245 + 12345;

return (unsigned int)(next/65536) % 32768;

}

void srand(unsigned int seed)

{

next = seed;

}

#include <stdio.h>

#include <time.h>

//Return a byte at a time of the rand() keystream

char randchar() {

static int key;

static int i = 0;

i = i % 4;

if (i == 0) key = rand();

return ((char *)(&key))[i++];

}

int main(int argc, const char* argv[]) {

static char randstate[64];

srand(time(NULL));

FILE *input, *output;

input = fopen("Homework1b.tex", "r");

output = fopen("Homework1b.tex.enc", "w");

int c,rc;

while ((c = fgetc(input)) != EOF) {

rc=randchar();

printf("c=%d (%c) and rc=%d ",c,c,rc);

fputc(c^rc,output);

}

fclose(input);

fclose(output);

}