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 +...
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”,...
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...
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...
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...
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 =...
Generate test cases for the following code by using Basic Path Testing. void sort(int a[ ],int...
Generate test cases for the following code by using Basic Path Testing. void sort(int a[ ],int N) {     int i,j,p,t;        for(i=0;i<N-1;i++)        {     p=i;               for(j=i+1;j<N;j++)                      if(a[j]>a[p]) p=j;               if(p!=i)               {     t=a[p];  a[p]=a[i];     a[i]=t;   }        } } a)       Draw CFG. b)       How many basic paths for the CFG? c)        List the basic paths. d)       Generate test cases from it.
Using the C programming language implement Heapsort in the manner described in class. Here is some...
Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided. /* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR |...
Using the program below, identify the values of pid at lines A, B, C, and D....
Using the program below, identify the values of pid at lines A, B, C, and D. (Assume that the actual pids of the parent and child are 2600 and 2603, respectively.)   #include <sys/types.h>   #include <stdio.h>   #include <unistd.h>      int main()   {   pid_t pid, pid1;        /* fork a child process */     pid = fork();        if (pid lt; 0) { /* error occurred */       fprintf(stderr, "Fork Failed");       return 1;     }     else if (pid == 0) { /* child process */       pid1 = getpid();       ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT