{VERSION 6 0 "IBM INTEL NT" "6.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 262 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Tim es" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" -1 12 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Author" -1 19 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 19 "CS 300 Assignment 4" }} {PARA 19 "" 0 "" {TEXT -1 45 "Due Thursday June 3 by the beginning of \+ class" }}{PARA 0 "" 0 "" {TEXT -1 7 "Name: " }}{PARA 0 "" 0 "" {TEXT -1 6 "Email:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 210 "Instructions: Fill in your name and email. Use submit to sub mit your worksheet. There are two questions with subparts (see the qu estions for the number of points and the number of points for the subp arts). " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 155 "Overview: The purpose of this assignment is to review modular ar ithmetic and the RSA public key cryptosystem, and to explore the FFT a nd its applications." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 16 "with(numtheory);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#7Q%&GIgcdG%)bigomegaG%&cfracG%)cfracpolG%+cyclotomicG%)divisorsG %)factorEQG%*factorsetG%'fermatG%)imagunitG%&indexG%/integral_basisG%) invcfracG%'invphiG%*issqrfreeG%'jacobiG%*kroneckerG%'lambdaG%)legendre G%)mcombineG%)mersenneG%(migcdexG%*minkowskiG%(mipolysG%%mlogG%'mobius G%&mrootG%&msqrtG%)nearestpG%*nthconverG%)nthdenomG%)nthnumerG%'nthpow G%&orderG%)pdexpandG%$phiG%#piG%*pprimrootG%)primrootG%(quadresG%+root sunityG%*safeprimeG%&sigmaG%*sq2factorG%(sum2sqrG%$tauG%%thueG" }}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 49 "Question 1 [60 points] (modular a rithmetic & RSA)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 256 19 "Part a (15 points) " }{TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 3 " " }}{PARA 0 "" 0 "" {TEXT -1 110 " Fermat's Theore m: Assume that p is a prime number, and gcd(a,p) = 1 (i.e. a is not \+ a multiple of p). " }}{PARA 0 "" 0 "" {TEXT -1 451 " Then a^(p-1 ) is equivalent to 1 mod p. An immediate corollary of this theorem i s that a^p = a mod p for all a.\n\n Verify, using Maple, that the theorem is true for some values of a and p. You can use the Maple f unction \"isprime\" to verify \"with high probability\"\n that a number is prime. For small numbers n, you can use the function \"ifa ctor\" to find all of the prime factors of n.\n \n1. Verif y that p = 9883 is prime." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 79 "2. Compute 3^(9882) mod 9883 (use the p ower function: Power(3,9882) mod 9883." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 352 "3. You can use Fermat's \+ theorem to prove that a number is not prime. If a^(n-1) is not equiva lent to 1 mod n, then n can not be prime. You should first compute t he gcd(a,n) to check that a and n are relatively prime (if not, then \+ you have found a factor of n). Use Maple's igcd function to compute i nteger gcds. Prove that 2^(30) + 1 is not prime." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 7 " " }}{PARA 0 "" 0 "" {TEXT -1 142 "4. Show t hat Power(2,2^(30)) mod 2^(30) + 1 = 1. This shows that Fermat's theo rem is not a sufficient test to verify that a number is prime.\n" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 134 "5. Use Fermat's theorem to wri te a Maple procedure to compute inverses in Z_p, where p is a prime. \+ Make sure you test your procedure." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 257 17 "Part b (5 points)" }{TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 143 " The Extended Euclidean Algorithm can be used to compute x and y such \+ that a*x + b*y = gcd(a,b). See the help information of igcd and igcde x.\n" }}{PARA 0 "" 0 "" {TEXT -1 44 "1. What is gcd(9883,7703) and gcd (17,3120)?\n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 15 " " }}{PARA 0 "" 0 "" {TEXT -1 174 " 2. Use the Maple function \"igcdex\" to find x and y such that 9883*x \+ + 7703*y = gcd(9883,7703). Verify that the result that you obtained \+ does in fact satisfy this equation.\n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 15 " " }} {PARA 0 "" 0 "" {TEXT -1 92 "3. Use the Maple function \"igcdex\" to f ind x and y such that 17*x + 3120*y = gcd(17,3120). " }}{PARA 0 "" 0 "" {TEXT -1 77 "Verify that the result that you obtained does in fact \+ satisfy this equation.\n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 " " }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 258 19 "Par t c (15 points) " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 132 " Modular inverses. If gcd(a,n) = 1 then by (2) there exi st x and y such that a*x + n*y = 1. Therefore a*x is equivalent to 1 \+ mod n." }}{PARA 0 "" 0 "" {TEXT -1 137 "\n1. Use the extended Euclide an Algorithm to find a solution (modular inverse) to 15*x = 1 mod 9883 . Compare this with (1/15) mod 9883.\n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 99 "2. Use the extended Euclidean Algorithm to find a soluti on (modular inverse) to 17*x = 1 mod 3120\n" }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 147 "3. Use the extended Euclidean Algorithm to write a Map le procedure to find inverses in Z_p, where p is a prime. Make sure y ou test your procedure." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT 259 18 "Part d (15 points)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 197 " The Euler phi function. The Euler phi function of a positive integer n, is the number of int egers 1 <= a < n such that gcd(a,n) = 1. Recall that igcd is Maple's \+ function to compute integer gcds." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 155 "\n1. Write a Maple procedure, using the \+ above definition, to compute phi(n). Test your procedure by comparing it with Maple's algorithm numtheory[phi](n).\n" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 4 " " }}{PARA 0 "" 0 "" {TEXT -1 107 "2. What is phi(9883), phi(53), phi(61)? What \+ is the pattern? What is phi(p^e), when p is a prime number?\n" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 116 "3. Verify that phi(53 * 61) = \+ 52 * 60. Verify that phi(a*b) = phi(a)*phi(b) when gcd(a,b)=1 for sev eral examples. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 " " 0 "" {TEXT -1 183 "4. Using the results of parts 2 and 3 write down \+ a formula for phi(n) when n = p_1^e_1 * ... * p_t^e_t, where p_i is a \+ prime number? Use your forumla to reimplement the phi function." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 260 18 " Part e (10 points)" }{TEXT -1 3 " . " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 94 "The RSA public key Cryptosystem. Let p = 53 and q = 61 and n = p*q. Let M = \"YOU ARE DONE\".\n" }}{PARA 0 "" 0 "" {TEXT -1 130 "1. Encode M as an integer (If a letter is the it h letter in the alphabet assign that letter the number i. Let blank e qual to 0. " }}{PARA 0 "" 0 "" {TEXT -1 44 " What is the integer c orresponding to M?\n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 64 "2. What i s phi(n)? Let e = 17. Verify that gcd(e,phi(n)) = 1.\n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 40 "3. Find d such that d*e = 1 mod phi(n). \n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 87 "4. Encrypt M using the RS A public key cryptosystem with the encryption key E = (e,n). " }} {PARA 0 "" 0 "" {TEXT -1 156 "Since the message to be encrypted has to be smaller than n, divide M into blocks corresponding to two letters \+ each and then encrypt each block separately.\n" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 343 "\nThe correc tness of this procedure is based on a generalization of Fermat's theor em. See the RSA paper for a proof and further discussion.\n\n \+ Theorem: M^\{k* phi(n) + 1\} = M mod n.\n\n \+ Since e and d have been chosen such that e * d = 1 mod phi(n) (i.e. \+ e*d = k*phi(n) + 1 for some k), this theorem implies that " }}{PARA 0 "" 0 "" {TEXT -1 165 " (M^e)^d = M^(ed) = M mod n.\n \+ \n 5.. Use the decryption key D = (d,n) to recover \+ the original message from the encrypted message.\n" }}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 28 "Qu estion 2 [40 points] (FFT)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 38 "In this question, you will investigate" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 263 19 "Part a) [10 po ints]" }{TEXT -1 407 " Primitive elements and nth roots. First use Ma ple's primroot function to find primitive elements mod 257. Recall th at a primitive element mod p, is an element of Z_p such that all of th e non-zero elements of Z_p are equal to powers of the primitive elemen t [alternatively the smallest positive integer power of a primitive el ement that is equal to 1 is p-1]. For example, 3 is a primtive elemen t mod 17." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 329 "In class it was shown that there exist nth roots of unity mod p, \+ for any n that divides (p-1). Write a Maple procedure called nthroot \+ which takes as input a prime p and returns an nth root of unity mod p \+ (if it exists). If such a root does not exist, or if the input is not prime, use the error statement to indicate the error." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "primroo t(257);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT 262 19 "Part b) [10 points]" }{TEXT -1 444 " Inverse DFT. Below is a Maple procedure to construct the DFT matrix mod p, given \+ a primtive nth root of unity. You will need to write a Maple procedur e to compute the inverse DFT of size n, given a primitive nth root of \+ unity. Test your procedure by verifying that the product of the DFT m atrix and the inverse DFT matrix is the identity matrix (don't forget \+ to reduce the elements of the product matrix mod p - you can use map t o do this)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 26 "Fouriermodp := proc(n,w,p)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 58 " linalg[matrix](n,n,(i,j)-> w^((i-1)*(j-1) mod n) mo d p);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%,FouriermodpGf*6%%\"nG%\"wG%\"pG6\"F*F*-&%'linalgG6#% 'matrixG6%9$F1f*6$%\"iG%\"jGF*6$%)operatorG%&arrowGF*-%$modG6$)T$-F:6$ *&,&F1\"\"\"FB!\"\"FB,&9%FBFBFCFBT&T(F*F*6(F(FEF'F1F)9&F*F*F*" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "Fouriermodp(4,3,17);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#K%'matrixG6#7&7&\"\"\"F(F(F(7&F(\"\"$ \"\"*\"#57&F(F+F(F+7&F(F,F+F*Q(pprint16\"" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT 261 19 "Part c) [20 points]" }{TEXT -1 512 " Polynomial multip lication mod p. Write a Maple procedure that multiplies two polynomia ls whose coefficients are in Z_p. Your procedure should be based on t he evaluation, pointwise product, and interpolation algorithm discusse d in class; however, you must use the FFT for evaluation and interpola tion. You will need to compute the smallest power of two (N = 2^k) th at provides sufficiently many evaluation points to compute the product . If Z_p does not contain a primitive Nth root of unity, return an er ror." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 372 " You may use the following implementation of mod p FFTs, though you sho uld verify that it works properly by comparing its output to the outpu t obtained by using the DFT matrix directly (i.e. multiply the input v ector by the DFT matrix corresponding to the FFT you want to compute). Make sure you reduce the elements of the output mod p after multiply ing by the DFT matrix." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "FFTmodp := proc(N,a,w,p)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 27 " local b,c,B,C,k,wk,i,n,A;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 31 " if (N = 1) then RETURN(a) fi;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 11 " n := N/2;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 32 " b := [seq(a[2*i+1],i=0..n-1)];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 35 " c := [seq(a[2*i+1+1],i=0..n-1)]; " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 32 " B := FFTmodp(n,b,w^2 mod p,p);" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 32 " C := FFTmodp(n,c,w^2 mod p,p);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 " A := [seq(0,k=0..N-1)];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 24 " for k from 0 to n-1 do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 27 " wk := Power(w,k) mod p;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 " A[k+1] := B[k+1] + wk*C[k+1] mod p; " }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 41 " A[n+k+1] := B[k+1] - wk*C[k+1] mod p;" } }{PARA 0 "> " 0 "" {MPLTEXT 1 0 5 " od;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 13 " RETURN(A); " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "en d;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%(FFTmodpGf*6&%\"NG%\"aG%\"wG% \"pG6+%\"bG%\"cG%\"BG%\"CG%\"kG%#wkG%\"iG%\"nG%\"AG6\"F5C+@$/9$\"\"\"- %'RETURNG6#9%>8+,$*&#F:\"\"#F:F9F:F:>8$7#-%$seqG6$&F>6#,&*&FDF:8*F:F:F :F:/FO;\"\"!,&F@F:F:!\"\">8%7#-FI6$&F>6#,&*&FDF:FOF:F:FDF:FP>8&-F$6&F@ FF-%$modG6$*$)9&FDF:9'Fbo>8'-F$6&F@FVF\\oFbo>8,7#-FI6$FR/8(;FR,&F9F:F: FT?(F]pFRF:FS%%trueGC%>8)-F]o6$-%&PowerG6$FaoF]pFbo>&Fho6#,&F]pF:F:F:- F]o6$,&&FinF\\qF:*&FdpF:&FdoF\\qF:F:Fbo>&Fho6#,(F@F:F]pF:F:F:-F]o6$,&F aqF:FbqFTFbo-F<6#FhoF5F5F5" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{MARK "3" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }