LAST NAME: FIRST NAME: Note: * is times, ^ is exponentiation, + is plus, - is minus, / is division, all log's are base 2 Note: problems are either 1 point or 2 points each, as labeled. (1) Let x = 12. List the positive integers less than x which have multiplicative inverses mod x. 1 point. Answer: all numbers x between 2 and 12 with gcd(x,12)=1. So 5,7,11 (2) Let b = 11, e = 10, n = 30. Compute (b^e) mod n. 1 point. Answer: use fast-mod-exp by repeated squaring. check answer on wolfram alpha (3) Let a = 5, b = 8. Compute a^(-1) mod b. 1 point. Answer: use extended euclidean algorithm, or guess and check. Make sure you get an answer y such that y*a = 1 mod b. Answer is y=5 (4) Let n = p*q with p and q prime. What are the requirements for e and d, the encryption exponent and decryption exponent? 1 point. Answer: Let phi(n)=(p-1)*(q-1). Then e is such that 1 b, (a*a) mod b = ((a mod b) * (a mod b)) mod b Note: this is true in general. giving an example is not sufficient to show it is true for every a and b. That is not a proof that it always works!!!!!!!!!!!!!!!!!! See how many ! I used. This is important!!! (8) Either prove the following or give a counter example. 1 point. For positive integers a, b with a > b, (a*a) mod b = (a*b) mod a Answer: this does not work in general. To show it doesn't always work, you just need to give an example where it doesn't work. Pick a=2, b=3. Then a*a mod b = 1. And a*b mod a = 0. Note: if you gave an example where they're the same, you got half credit. (9) Put the following in order from fastest to slowest, in terms of big-O running time, where x and y are positive integers having bit-length n. 2 points total (a) x*y using Karatsuba multiplication (b) x+y, addition (c) x*y using grade-school multiplication (d) List all binary strings of length x (e) Fermat prime test of x, using grade-school multiplication (f) gcd(x,y), using grade-school multiplication for multiplication (g) Prime testing x using trial division Correct order is b,a,c,e,f,g,d. e and f are about the same, so you could have put those in either order. I counted the largest subset that you had in the right order. You got full credit if you only had one misplaced, 3/4 credit if 2 or 3 misplaced, 1/2 credit if 4 misplaced, 1/4 credit if all but 1 or 2 misplaced. Note: need to pay attention to running time as a function of bit length!! (10) Give C code for the following functions. 2 points each // return the gcd of a and b, using Euclid's algorithm int gcd(int a, b) { Answer: see wikipedia, etc. Notes: mod doesn't work in C, need %. if doing recursive version, need to return gcd(b,a%b), not just call gcd(b,a%b). also need to make sure to return a if b==0. Notes: -1/2 if base case was wrong, -1 if logic is wrong. } // return b^e mod n, using fast modexp by repeated squaring int modExp(int b, int e, int n) { Answer: see wikipedia, etc. Similar grading as in last question. Notes: you don't need to compute the binary representation first. Just look at the bits of e as you shift it to the right. Computing the binary representation first is wasteful, essentially doubling the running time; and the way most of you did it limits it to work only for 64 bit integers. } (11) Evaluate the following. 1/2 point each. 1 + 3 + 9 + 27 + ... 3^10 Answer: (3^11-1)/(3-1) 5 + 10 + 15 + ... + 5*100 Answer: 5*(101*100/2) Number of bits in one gigabyte Answer: 8*2^30 (2^30 / 2^10)^4 Answer: 2^80 log(16^3) Answer: 12*log(2) = 12, since we're assuming base 2 log.