10.07.2015 Views

Implementing the RSA cryptosystem with Maxima CAS - Facultad de ...

Implementing the RSA cryptosystem with Maxima CAS - Facultad de ...

Implementing the RSA cryptosystem with Maxima CAS - Facultad de ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The Electronic Journal of Ma<strong>the</strong>matics and Technology, Volume 6, Number 1, ISSN 1933-28232.2 The Chinese remain<strong>de</strong>r <strong>the</strong>oremThe original form of <strong>the</strong> <strong>the</strong>orem, appearing in a book written by <strong>the</strong> Chinese ma<strong>the</strong>matician QinJiushao and published in 1247, is a result related to systems of congruences. It is possible to find aprece<strong>de</strong>nt in <strong>the</strong> Sunzi suanjing, a book from <strong>the</strong> third century written by Sun Zi:Han Xing asks how many soldiers are in his army. If you let <strong>the</strong>m para<strong>de</strong> in rows of 3soldiers, two soldiers will be left. If you let <strong>the</strong>m para<strong>de</strong> in rows of 5, 3 will be left, andin rows of 7, 2 will be left. How many soldiers are <strong>the</strong>re?.The mo<strong>de</strong>rn formulation of <strong>the</strong> problem is <strong>the</strong> following. Let m 1 , m 2 , ..., m k be integers that aregreater than one and pairwise coprime, and let a 1 , a 2 , ..., a k be any integers. Then <strong>the</strong>re exists aninteger x such that x ≡ a i (mod m i ) for each i ∈ {1, 2, ..., k}. Fur<strong>the</strong>rmore, for any o<strong>the</strong>r integer ythat satisfies all <strong>the</strong> congruences, y ≡ x (mod M) where M = m 1 · · · m k . Note that <strong>the</strong>re is only onesolution in {0, 1, ..., M}.The proof of <strong>the</strong> <strong>the</strong>orem (which can be found in Theorem 5.26 of [1]) gives an algorithm to findx. The following co<strong>de</strong> implements it in <strong>Maxima</strong> (it returns <strong>the</strong> lowest positive solution modulo M):Beginning of co<strong>de</strong>chinese_remain<strong>de</strong>r(a,k):=block([K,L,x],K:makelist(apply("*",<strong>de</strong>lete(k[i],k)),i,1,length(k)),L:makelist(first(gc<strong>de</strong>x(K[i],k[i])),i,1,length(k)),x:mod(sum(a[i]*K[i]*L[i],i,1,length(k)),apply("*",k)),x);End of co<strong>de</strong>To use it, just write chinese remain<strong>de</strong>r([a1,...,ar],[m1,...,mr]). For <strong>the</strong> HanXing’s example:(%i4)chinese_remain<strong>de</strong>r([2,3,2],[3,5,7]);(%o4) 23A small army, in<strong>de</strong>ed. Surely, this is one example in which <strong>the</strong> solution is not <strong>the</strong> one in {0, 1, ..., M}(as in this case Han Xing would have not nee<strong>de</strong>d to ask for <strong>the</strong> number of soldiers, being easy to count<strong>the</strong>m by himself), but one of <strong>the</strong> infinite numbers congruent <strong>with</strong> 23 modulo M = 7 · 5 · 3 = 105, thatis: 128, 233, etcetera.2.3 Euler’s <strong>the</strong>oremConsi<strong>de</strong>r Example 4 again. What if we are asked for <strong>the</strong> last digit in base 77?. We can not applyFermat’s <strong>the</strong>orem here, because 77 is composite. Euler found a generalization of Fermat’s <strong>the</strong>orem tothis case, introducing his totient function ϕ(n) (which gives <strong>the</strong> number of positive integers less than38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!