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

#include <stdio.h> #include <stdlib.h> #include <string.h> void explode(const in

ID: 3886642 • Letter: #

Question

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void explode(const int code);

void readInput(char buffer[], const int bufferSize){

int i;

int c;

for(i=0; i<=bufferSize; ++i){

c = getchar();

/* this checks that you are at the end of the line */

/* Windows encodes an end-of-line as two characters: */

/* Linux just uses */

/* This will accept either version */

if(c == ' '){

c = getchar();

}

if(c == ' '){

break;

}

else if(i<bufferSize){

buffer[i] = (char)c;

}

}

}

void part5(char buffer[], const int bufferSize){

const char allowed[] = "a3hUD6Cc8bTzv";

int i, j, x;

for(i=0; i<bufferSize; ++i){

char c;

x = getchar();

if(x == EOF)

explode(10);

else if(x == ' ')

explode(11);

c = (char)x;

for(j=2; j<10; ++j){

if(c == allowed[j]){

buffer[i] = c + 1;

break;

}

}

if(j == 10){

explode(12);

}

}

j = 0;

for(i=1; i<bufferSize; ++i){

if(buffer[i] != buffer[i-1]){

j = 1;

break;

}

}

if(j == 0)

explode(13);

/* Windows encodes an end-of-line as two characters: */

/* Linux just uses */

/* This will accept either version */

x = getchar();

if(x == ' ')

x = getchar();

if(x != ' ')

explode(14);

}

void part6(const char buf1[], const int bufSize){

char buf2[bufSize];

int i, c;

readInput(buf2, bufSize);

for(i=0; i<bufSize; ++i){

if(buf1[i] != buf2[bufSize - 1 - i])

explode(-44);

}

}

void theBomb(){

const int bufSize = 10;

char buffer[bufSize];

int result;

printf("Enter the stage 5 password: ");

part5(buffer, bufSize);

printf("Stage 5 defused. ");

printf("Enter the stage 6 password: ");

part6(buffer, bufSize);

printf("Stage 6 defused. ");

printf("The entire bomb has been defused. ");

}

Explanation / Answer

The password for stage 5 is as follows:

a3hUD6Cc8bTzv


The password for stage 6 is as follows:

b4iVE7Dd9cU{x

This is because whatever we input at stag5 is stored with a 1 added to the input charcter