{"id":138,"date":"2008-07-02T05:42:57","date_gmt":"2008-07-02T05:42:57","guid":{"rendered":"http:\/\/www.blueraja.com\/blog2\/?p=138"},"modified":"2012-03-09T18:58:21","modified_gmt":"2012-03-09T23:58:21","slug":"rsa-encryption-part-2","status":"publish","type":"post","link":"https:\/\/www.blueraja.com\/blog\/138\/rsa-encryption-part-2","title":{"rendered":"RSA Encryption, Part 2"},"content":{"rendered":"<p>Ah, welcome back my vigilant peons.  Today we will be continuing the topic of our last discussion:  modular arithmetic.  Throughout this discussion, we will assume all numbers are integers.<\/p>\n<p><span class=\"heading\">2. Euler&#8217;s &Phi; Function<\/span><br \/>\nIf you&#8217;ll recall, the last fun-filled example we gave was to find the last digit of <span class=\"equation\">3<sup>403<\/sup><\/span> &#8211; we did this simply by noting that <span class=\"equation\">3<sup>4<\/sup> &equiv; 1 (mod 10)<\/span> and following some simple logic.  Today we generalize this technique.<\/p>\n<p><strong>Euler&#8217;s Phi<\/strong> (pronounced &quot;<em>fee<\/em>&quot;) <strong>Function &Phi;(n)<\/strong> is the count of the positive integers less than n that are <em>relatively prime<\/em> to n.  &#8220;Wait,&#8221; I hear you say, in a pathetically clueless tone, &#8220;what does it mean for two numbers to be relatively prime?&#8221;  Well, my young padawan, if you&#8217;ll recall from 4th grade mathematics, two numbers are relatively prime if their greatest common divisor (GCD) is 1 &#8211; however, even if you don&#8217;t remember this, it&#8217;s not terribly important.  Just know that if the larger of the two numbers is prime, then they will always be relatively prime to one another.<\/p>\n<p>Here&#8217;s a quick quiz &#8211; if n is prime, what is &Phi;(n)?<br \/>\nIf you&#8217;re wracking your brain for this one, then you&#8217;re not listening carefully enough.  I just told you that if n is prime, then all positive integers less than it are relatively prime to it; since there are n-1 integers less than n,<br \/>\n<span class=\"equation\">&Phi;(n) = n-1 (if n is prime)<\/span>.<br \/>\nAlthough the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Euler%27s_totient_function#Computing_Euler.27s_function\" target=\"_blank\">general formula<\/a> for &Phi;(n) isn&#8217;t important for our purposes, I will state (though I know I haven&#8217;t been the most trustworthy person in the past, you&#8217;re just going to have to take my word on this one) that if n is the product of two primes, say <span class=\"equation\">n=p*q<\/span> (p and q both primes), then <span class=\"equation\">&Phi;(n) = (p-1)(q-1)<\/span>.<\/p>\n<p>Here&#8217;s the point of all this &#8211; Euler discovered a neat little formula (aptly named <strong>Euler&#8217;s Formula<\/strong>) which says that, if a and n are relatively prime (there&#8217;s that word again!), then<br \/>\n<span class=\"equation\">a<sup>&Phi;(n)<\/sup> &equiv; 1 (mod n)<\/span><br \/>\nThe proof of this is fairly simple (in fact, if you know group theory, it consists of literally four words); however, since we&#8217;re all so new to this whole modular arithmetic thing anyways, and since we all know that these so-called &#8220;<em>proofs<\/em>&#8221; should really only be handled by those lowly peasants of <em>pure-mathematics<\/em> &#8211; high class folk like us are only interested in the blatent, ignorant facts &#8211; we won&#8217;t dirty our precious hands any more than we have to.<\/p>\n<p>Let&#8217;s put our new theorem to use: say we want to find the value of <span class=\"equation\">3<sup>123<\/sup> (mod 77)<\/span>.  We note that 77 is the product of two primes; thus,<br \/>\n<span class=\"equation\">&Phi;(77) = (7-1)(11-1) = 60<\/span>.<br \/>\nTherefore,<br \/>\n<span class=\"equation\">3<sup>60<\/sup> &equiv; 1 (mod 77)<\/span>, and<br \/>\n<span class=\"equation\">3<sup>123<\/sup> &equiv; (3<sup>60<\/sup>)<sup>2<\/sup> * 3<sup>3<\/sup> &equiv; (1)<sup>2<\/sup> * 27 &equiv; 27 (mod 77)<\/span>.<\/p>\n<p>Notice carefully what we did there.  We realized by Euler&#8217;s Formula that <span class=\"equation\">3<sup>&Phi;(77)<\/sup> &equiv; 1 (mod 77)<\/span>, so we were able to keep taking out <span class=\"equation\">3<sup>60<\/sup><\/span> from <span class=\"equation\">3<sup>123<\/sup><\/span> until we couldn&#8217;t take it out anymore.  That is, we converted <span class=\"equation\">3<sup>123<\/sup><\/span> to <span class=\"equation\">3<sup>123 mod &Phi;(77)<\/sup><\/span> without changing its value (mod 77).  It&#8217;s not hard to convince yourself that this is true in general; that is, if we&#8217;re trying to find the value of <span class=\"equation\">a<sup>k<\/sup> (mod n)<\/span>, then<br \/>\n<span class=\"equation\">a<sup>k<\/sup> &equiv; a<sup>k mod &Phi;(n)<\/sup> (mod n)<\/span><\/p>\n<p>As we will see next post, it is this final formula that allows us to encrypt and decrypt messages in RSA encryption.<\/p>\n<p><a href=\"http:\/\/www.blueraja.com\/blog\/140\/rsa-encryption-part-3\">Go on to part 3&#8230;<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ah, welcome back my vigilant peons. Today we will be continuing the topic of our last discussion: modular arithmetic. Throughout this discussion, we will assume all numbers are integers. 2. Euler&#8217;s &Phi; Function If you&#8217;ll recall, the last fun-filled example we gave was to find the last digit of 3403 &#8211; we did this simply [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/posts\/138"}],"collection":[{"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/comments?post=138"}],"version-history":[{"count":2,"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/posts\/138\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blueraja.com\/blog\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}