Question

void phase03(){ int a = atoi(next_input()); int b = atoi(next_input()); int c = atoi(next_input()); int d...

void phase03(){

int a = atoi(next_input());

int b = atoi(next_input());

int c = atoi(next_input());

int d = atoi(next_input());

int targ =

1 << ((hash % 7)+24) |

1 << (hash % 17) |

1 << (hash % 19);

int shot =

1 << a |

1 << b |

1 << c |

1 << d;

int hit = shot ^ targ;

hit = !hit;

if(hit){

return;

}

failure("Shifty bits hit? Xor not it seems...");

}

void substring(char *dest, char *src, int start, int stop, int max){

int i;

for(i=0; i<(stop-start) && i

dest[i] = src[start+i];

}

if(i==max){

fprintf(stderr,"ERROR: substring reached max %d for source string '%s' start:%d end:%d\n",

max,src,start,stop);

exit(1);

}

dest[i] = '\0';

}

what is the value of a, b, c, d in order for phase03() function to work

Hash Value: 2002296385

Homework Answers

Answer #1

The different ways we can assign values to a,b,c,d for the function to work properly are
1. {a,b,c,d} values can be assigned from {5,29}
but remember that there must be atleast one variable having value 5 and also there must be at least one variable having 29.

it can be from {5,29,29,29} , {5,5,29,29}, {5,5,5,29}
Let's take the first case
{a,b,c,d} = {5,29,29,29} , it is not mandatory that 'a' variable should be assigned 5 only , it could be assigned to b,c and d also .But exclusively. Once a value is assigned , it must be excluded from selection process.

Approach:
I have used Backward approach to solve the problem
1.Our function must execute without any error( i.e last statement shows the error), to prevent it, the error must not be reached.
2.It must be returned back to calling function before the error gets encountered.
3.We can see clearly, the if statement body has the return statement.To reach the control inside if statement, the condition 'hit' must be true
4.But before the if statement, 'hit' was notted with '!', so the initial value of hit must be zero so that on notting(!), it will be a 1(True).
5.Let's go to the before the statement. The hit value is evaluated from the XOR operation of shot and targ. Our requirement is the hit value to be zero. We know clearly that XOR of any two elements is zero only if they both are equal.So shot and targ must be equal so that shot^targ=0
6.We can calculate the targ value from the hash value
substitute the given hash value =2002296385
int targ = 1 << ((hash % 7)+24) | 1 << (hash % 17) | 1 << (hash % 19);
which will result in targ=536870944
7. We need to make shot value from left shift operations such that, it will be equal to targ
targ in binary 100000000000000000000000100000

The shot value is made up by OR operations of values 1<<a , ... 1<<d. So individual operations (1<<a) must contribute to set 1 at desired position.
8.We can clearly see the 6th bit from right is set(=1) and 30 th bit from right is set.
So shift 1, five times to the left. ie 1<<5 will result in 10000(6th bit will be set) and also shift 1, twenty nine times to the left. ie 1<<29 will result in 1 followed by 29 zeroes , so 30th bit will be 1.
9.Finally OR of the individual values(1<<a |1<<b|1<<c|1<<d) to get the value which is same as targ value
we should not alter any other bits, otherwise, it would not be equal to targ, then our function will fail. so we select values only from 5 and 29.

I hope I have written as best as I can so that it will be very clear for you to understand ?.

I am eagerly waiting for your valuable feedback ?. Thank you.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char *b[]) { 6 int c = atoi(a[0]); 7 for (int i = 0; i < c && b[i]; ++i) { 8 printf("%s", b[i]+2); 9 } 10 } 11 12 void main(int argc, char *argv[]) { 13      14 switch (argc) { 15 case 1: 16 for (int i = 0; environ[i]; ++i) {    17 printf("%s\n", environ[i]); 18 } 19 break; 20 default: 21 output(argv +...
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void Ge
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void GenerateFromArray(void); /************************************************************************************/ /************************************************************************************/ int main(void) { /* This is the main() program. It should call the functions ScanArray() and GenerateFromArray() */ GenerateFromArray(); system("pause"); return 0; } /*************************************************************************************** Define this function to scan the elements of an array from the given data file "ArrayInp.dat". If the input file is not found, or contains invalid data, the function should return a 0 and print an error message. If the input...
CS4315 Operating Systems Lab 2: Linux Processes This lab assignment contains three questions. To submit this...
CS4315 Operating Systems Lab 2: Linux Processes This lab assignment contains three questions. To submit this lab assignment, please use a Word document to include the screenshots and write your answer. 1. Run the following C program, and submit a screenshot of the result. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int main( ) { pid_t pid; if ( (pid = fork()) == 0 ) { printf (ā€œI am the child, my pid = %d and my parent pid = %d\nā€,...
Consider the following function: 01: void cpUniq (const int* source, int N, vector<int>& dest) 02: {...
Consider the following function: 01: void cpUniq (const int* source, int N, vector<int>& dest) 02: { 03: list<int> L; 04: for (int i = 0; i < N; ++i) 05: { 06: copy (source, source + i, front_inserter<int>(L)); 07: } 08: for (int j: L) 09: { 10: if (find(dest.begin(), dest.end(), j) != dest.end()) 11: dest.push_back(j); 12: } 13: } and the following list of complexity values: A: O(1), B: O(log N), C: O(N), D: O(N log N), E: O(N2),...
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ā€b = ā€ << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
2. Consider the following program written in C syntax: void swap(int a, int b) {   ...
2. Consider the following program written in C syntax: void swap(int a, int b) {    int temp;    temp = a;    a = b;    b = temp; } void main() {    int value = 2, list[5] = {1, 3, 5, 7, 9};    swap(value, list[0]);    swap(list[0], list[1]);    swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three...
Design flow chart of this code and make sure it is not handwritten it must on...
Design flow chart of this code and make sure it is not handwritten it must on some software. struct user {    int id;    int age;    bool annualClaim;    int plan;    char name[30];    char contactNum[15];    char address[50]; }; #define MAX_LENGTH 500 struct user users[100]; int userCount = 0; struct claim {    int id;    int claimedYear;    int amountClaimed;    int remaininigAmount; }; struct claim claims[100]; void loadData() {    char line[MAX_LENGTH];    const...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT