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

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.

#### Earn Coins

Coins can be redeemed for fabulous gifts.

##### Need Online Homework Help?

Most questions answered within 1 hours.