{"id":1400,"date":"2010-12-11T22:34:23","date_gmt":"2010-12-12T02:34:23","guid":{"rendered":"http:\/\/www.acarlstein.com\/?p=1400"},"modified":"2010-12-16T14:53:32","modified_gmt":"2010-12-16T18:53:32","slug":"introduction-to-network-security-%e2%80%93-part-9","status":"publish","type":"post","link":"http:\/\/blog.acarlstein.com\/?p=1400","title":{"rendered":"Introduction to Network Security \u2013 Part 9"},"content":{"rendered":"<p><strong>NOTIFICATION:<\/strong><strong> <\/strong>These examples are provided for educational purposes. The use of this code and\/or information is under your own responsibility and risk. The information and\/or code is given \u2018as is\u2019. I do not take responsibilities of how they are used. You are welcome to point out any mistakes in my posting and\/or leave a comment.<\/p>\n<p>Some of the mathematical tools (known as number theory) use in network security are prime numbers, greatest common divisor (GCD), Fermat&#8217;s theorem, Euler Totient function and theorem, primality testing and Miller Rabin algorithm.<\/p>\n<p><strong>Prime Number<\/strong><\/p>\n<p>A prime number is an integer <em>p<\/em> greater than 1 which can only be divided by 1 and itself.<\/p>\n<p>Formally speaking:<\/p>\n<p>&#8220;A prime number (or prime integer, often simply called a &#8220;prime&#8221; for short) is a\u00a0<a href=\"http:\/\/mathworld.wolfram.com\/PositiveInteger.html\">positive integer<\/a> <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mathworld.wolfram.com\/images\/equations\/PrimeNumber\/Inline1.gif\" border=\"0\" alt=\"p&gt;1\" width=\"30\" height=\"14\" \/> that has no positive integer\u00a0<a href=\"http:\/\/mathworld.wolfram.com\/Divisor.html\">divisors<\/a> other than 1 and\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mathworld.wolfram.com\/images\/equations\/PrimeNumber\/Inline2.gif\" border=\"0\" alt=\"p\" width=\"8\" height=\"14\" \/> itself. &#8221; &lt;<a href=\"http:\/\/mathworld.wolfram.com\/PrimeNumber.html\" target=\"_blank\">http:\/\/mathworld.wolfram.com\/PrimeNumber.html<\/a>&gt;<\/p>\n<p>An example of prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, &#8230;<\/p>\n<p>An example of numbers that are not prime: 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, &#8230;<\/p>\n<p>In the website Math.com you can find a prime number calculator that can tell you if a number is prime or not: &lt;<a href=\"http:\/\/www.math.com\/students\/calculators\/source\/prime-number.htm\" target=\"_blank\">http:\/\/www.math.com\/students\/calculators\/source\/prime-number.htm<\/a>&gt;<\/p>\n<p>One of the ways we can use prime numbers is to factorize a number in a unique way:<\/p>\n<p>Any number <em>a<\/em> greater than 1 can be factored in a unique way using prime <em>p<\/em> numbers while each consecutive prime number is greater than the previous prime number and their consecutive exponents <em>b<\/em> are one greater that then previous:<\/p>\n<pre>a = p1^b1 * p2^b2 * ... * pn^bn while p1 &lt; p2 &lt; ... &lt; pn and (b1, b2, ..., bn) &gt; 0<\/pre>\n<p>For example:<\/p>\n<ol>\n<li>\n<pre>a = 91 = p1 ^ b1 * p2 ^ b2 = 7 ^ 1 * 13 ^ 1 = 7 * 13\r\nTherefore, P1 = 7 and P2 = 13<\/pre>\n<\/li>\n<li>\n<pre>a = 3600 = p1 ^ b1 * p2 ^ b2 * p3 ^ b3 = 2^4 * 3^2 * 5^2\r\nTherefore, P1 = 2, P2 = 3, and P3 = 5<\/pre>\n<\/li>\n<\/ol>\n<p><strong>Greatest Common Divisor (GCD)<\/strong><\/p>\n<p>The greatest common divisor (gcd) is a number in which you can divide two positive numbers <em>a<\/em> and <em>b<\/em> and at the same time is common in <em>a<\/em> and <em>b<\/em>.<\/p>\n<p>Formally Speaking:<\/p>\n<p>&#8220;The greatest common divisor &#8230; of two positive integers\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mathworld.wolfram.com\/images\/equations\/GreatestCommonDivisor\/Inline1.gif\" border=\"0\" alt=\"a\" width=\"7\" height=\"14\" \/> and\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mathworld.wolfram.com\/images\/equations\/GreatestCommonDivisor\/Inline2.gif\" border=\"0\" alt=\"b\" width=\"7\" height=\"14\" \/> is the largest <a href=\"http:\/\/mathworld.wolfram.com\/Divisor.html\">divisor<\/a> common to\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mathworld.wolfram.com\/images\/equations\/GreatestCommonDivisor\/Inline3.gif\" border=\"0\" alt=\"a\" width=\"7\" height=\"14\" \/> and\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mathworld.wolfram.com\/images\/equations\/GreatestCommonDivisor\/Inline4.gif\" border=\"0\" alt=\"b\" width=\"7\" height=\"14\" \/>. &#8221; &lt;<a href=\"http:\/\/mathworld.wolfram.com\/GreatestCommonDivisor.html\" target=\"_blank\">http:\/\/mathworld.wolfram.com\/GreatestCommonDivisor.html<\/a>&gt;<\/p>\n<p>There are different ways to obtain the greatest common divisor such as using prime factorizations, Euclid&#8217;s algorithm, and others &lt;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Greatest_common_divisor\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Greatest_common_divisor<\/a>&gt;.<\/p>\n<p><span style=\"text-decoration: underline;\">Approach 1:<\/span><\/p>\n<p>A way to determine the greatest common divisor of two integers <em>a<\/em> and <em>b<\/em> is by<br \/>\ncomparing the prime factorization of <em>a<\/em> and <em>b<\/em> and using their least powers.<\/p>\n<p>Lets assume we wish to obtain the greatest common divisor of 12 and 30, gcd(12, 30).<\/p>\n<p>For 300, we obtain the following prime numbers:<\/p>\n<pre>30 = 2^1 * 3^1 * 5^1<\/pre>\n<p>For 12, we obtain the following prime numbers:<\/p>\n<pre>12 = 2^1 * 3^1 = 2^1 * 3^1 * 5^0<\/pre>\n<p>In both cases, we have that 2 and 3 are the prime numbers used in <em>a<\/em> and <em>b<\/em>.<br \/>\nAlso, we have that 2^1 and 3^1 are their least powers. Therefore,<\/p>\n<pre>gcd(12, 30) = 2^1 * 3^1 = 6<\/pre>\n<p><span style=\"text-decoration: underline;\">Approach 2:<\/span><\/p>\n<p>The follow is a more friendly approach to obtain the greates common divisor.<br \/>\nLets assume we wish to know the greatest common denominator of 7 and 160, gcd(7, 160)<\/p>\n<ol>\n<li>Write down this formula:<br \/>\n<em> (Dividend) = (Divisor) * (Quotient) + (Remainder)<\/em><\/li>\n<li>The greatest number will be the dividend:<br \/>\nDividend = 160<br \/>\n<em> (<span style=\"color: #0000ff;\">160<\/span>) = (Divisor) * (Quotient) + (Remainder)<\/em><\/li>\n<li>The other number will be the divisor:<br \/>\nDivisor = 7<br \/>\n<em> (<span style=\"color: #0000ff;\">160<\/span>) = (<span style=\"color: #0000ff;\">7<\/span>) * (Quotient) + (Remainder)<\/em><\/li>\n<li>Multiply the divisor with a quotient that would get you a number as close as possible to the dividend<br \/>\nIf 160\/7 = 22.8571429 then use 22 for the quotient<br \/>\n<em> (<span style=\"color: #0000ff;\">160<\/span>) = (<span style=\"color: #0000ff;\">7<\/span>) * (<span style=\"color: #0000ff;\">22<\/span>) + (Remainder)<\/em><\/li>\n<li>The remainder will be the number that you need to reach 160. Since 7 * 22 is 154 the remainder is 6<br \/>\n<em>(<span style=\"color: #0000ff;\">160<\/span>) = (<span style=\"color: #0000ff;\">7<\/span>) * (<span style=\"color: #0000ff;\">22<\/span>) + (<span style=\"color: #0000ff;\">6<\/span>)<\/em><\/li>\n<li>Now the Divisor became the new dividend and the remainder became the new divisor:<br \/>\nNew dividend = 7 (previous divisor)<br \/>\nNew divisor = 6 (previous remainder)<br \/>\n<em> (<span style=\"color: #0000ff;\">7<\/span>) = (<span style=\"color: #0000ff;\">6<\/span>) * (Quotient) + (Remainder)<\/em><\/li>\n<li>Repeat the process, get a quotient that would multiply the divisor (6) as close as possible to the dividend (7)<br \/>\n<em>(<span style=\"color: #0000ff;\">7<\/span>) = (<span style=\"color: #0000ff;\">6<\/span>) * (<span style=\"color: #0000ff;\">1<\/span>) + (Remainder)<\/em><\/li>\n<li>The remainder would be 1. This remainder is the greatest common divisor between 7 and 160<br \/>\n<em><span style=\"color: #0000ff;\"> gcd(7, 160) = 1<\/span><\/em><\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\"><em>Y<\/em>ou can find a gcd calculator here:<\/span><br \/>\n&lt;<a href=\"http:\/\/britton.disted.camosun.bc.ca\/gcdlcm\/jbgcdlcm.htm\" target=\"_blank\">http:\/\/britton.disted.camosun.bc.ca\/gcdlcm\/jbgcdlcm.htm<\/a>&gt;<\/p>\n<p><strong> Fermat&#8217;s Theorem<\/strong><\/p>\n<p>Before going over the Fermat&#8217;s theorem, let review an old concept related with this topic, modular arithmetic.<\/p>\n<p>Modular arithmetic (also known as clock arithmetic), is a system in which numbers &#8220;wrap around&#8221; after reaching a certain value. Of this system, we use the congruence relation on integer known as modulus.<\/p>\n<p>Formally speaking:<br \/>\n&#8220;For a positive integer <em>n<\/em>, two integers <em>a<\/em> and <em>b<\/em> are said to be congruent modulo <em>n<\/em>, (<em>a = b mod n<\/em>),<br \/>\nif their difference <em>a \u2212 b<\/em> is an integer multiple of <em>n<\/em>. The number n is called the modulus of the congruence&#8221; &lt;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Modular_arithmetic#Congruence_relation\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Modular_arithmetic#Congruence_relation<\/a>&gt;<\/p>\n<p>For Example:<\/p>\n<ol>\n<li>\n<pre>Lets assume we have a = 100, b = 86, and n = 7 such that 100 = 86 (mod 7).<\/pre>\n<\/li>\n<li>\n<pre>100 - 86 = 14 in which 14 has 7 as a divisor.<\/pre>\n<\/li>\n<li>\n<pre>If we divide 100 by 7,\r\nwe find out that the quwootient is 14 and remainder is 2.<\/pre>\n<\/li>\n<li>\n<pre>Just coincidence, if we have 100 = 2 (mod 7),\r\nwe also find out that the remainder (b) is two too.<\/pre>\n<\/li>\n<\/ol>\n<p>Another way to see the previous example is as follows:<\/p>\n<pre>100 = 86 (mod 7)\r\n\r\nMeans that 100 and 86 leave the same remainder when you divide by\r\n7; or, equivalently, that their difference is a multiple of 7.\r\n\r\nHere is a link in which you can find the quotient and remainder of a division:\r\n&lt;<a href=\"http:\/\/www.analyzemath.com\/Calculators_3\/quotient_remainder.html\" target=\"_blank\">http:\/\/www.analyzemath.com\/Calculators_3\/quotient_remainder.html<\/a>&gt;<\/pre>\n<p>Another example:<\/p>\n<ol>\n<li>\n<pre>For a = 0 mod 5, If a = 0 mod 5 then a^4 = 0^4 = 0 mod 5<\/pre>\n<\/li>\n<li>\n<pre>For a = 1 mod 5, if a = 1 mod 5 then a^4 = 1^4 = 1 mod 5<\/pre>\n<\/li>\n<li>\n<pre>For a = 2 mod 5, if a = 2 mod 5 then a^4 = 2^4 = 16 = 1 mod 5<\/pre>\n<\/li>\n<li>\n<pre>For a = 3 mod 5, if a = 3 mod 5 then a^4 = 3^4 = 81 = 1 mod 5<\/pre>\n<\/li>\n<li>\n<pre>For a = 4 mod 5, if a = 4 mod 5 then a^4 = 4^4 = 256 = 1 mod 5<\/pre>\n<\/li>\n<\/ol>\n<p>Now that we have an idea about modulus, we can begin talking about Fermat&#8217;s Theorem.<\/p>\n<p>Fermat&#8217;s theorem also known as &#8220;Fermat&#8217;s little theorem&#8221; (do not confuse with &#8220;Fermat&#8217;s last theorem&#8221;), establish that:<\/p>\n<ol>\n<li> If <em>p<\/em> is a prime number and for any integer <em>a<\/em> lower than the prime number <em>p, a&lt;p<\/em> is a positive integer not divisible by the prime number <em>p.<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1409\" title=\"Screenshot\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot.png\" alt=\"\" width=\"103\" height=\"21\" \/><\/a><br \/>\n<\/em><\/li>\n<li>Or<em>, <\/em>if <em>p<\/em> is a prime number then for any integer <em>a<\/em>, <em>a^p<\/em> <em>&#8211; a<\/em> will be evenly divisible by <em>p<\/em>.<br \/>\n<img decoding=\"async\" src=\"http:\/\/upload.wikimedia.org\/math\/7\/2\/b\/72b96b73d45f415cebed39c857204494.png\" alt=\"a^p \\equiv a \\pmod{p}.\\,\\!\" \/><\/li>\n<li>Or, if <em>p<\/em> is a prime and <em>a<\/em> is an integer relatively prime to <em>p<\/em>, then <em>[a^(p\u22121)] \u2212 1<\/em> will be evenly divisible by <em>p<\/em>.<br \/>\n<img decoding=\"async\" src=\"http:\/\/upload.wikimedia.org\/math\/a\/2\/5\/a257bad1e90b56abcc9ab047b1911b6f.png\" alt=\"a^{p-1} \\equiv 1 \\pmod{p}.\\,\\!\" \/><\/li>\n<\/ol>\n<p>(&lt;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Fermat%27s_little_theorem\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Fermat&#8217;s_little_theorem<\/a>&gt;)<\/p>\n<p>For example:<\/p>\n<ol>\n<li>\n<pre>Lets assume p = 3 and a = 2Fermat's little theorem establish that<\/pre>\n<\/li>\n<li>\n<pre><em><a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot.png\" alt=\"\" width=\"103\" height=\"21\" \/><\/a><\/em><\/pre>\n<\/li>\n<li>\n<pre>Then a^(p-1) = 2^(3 - 1) = 2^2 = 4<\/pre>\n<\/li>\n<li>\n<pre>So, 1 = a^(p-1) mod p = 4 mod 3 = 1<\/pre>\n<\/li>\n<\/ol>\n<p>In network security, Fermat&#8217;s little theorem is used in public key and primality testing.<\/p>\n<p><strong>Euler Totient Function <em>\u00f8(n)<\/em><\/strong><\/p>\n<p>The Euler Totient function is represented by <em>\u00f8<\/em>(<em>n<\/em>) or \u03c6(<em>n<\/em>) depending the author.<\/p>\n<p>The Euler Totient function establish that:<\/p>\n<ol>\n<li><em>\u00f8<\/em>(<em>n<\/em>) is the number of possitive integers less than <em>n<\/em> and coprime (also known as relatively prime) to <em>n<\/em><\/li>\n<li>Or the number of positive integers less or equal to <em>n<\/em> that are relatively prime to <em>n<\/em>, where 1 is counted as being coprime (relatively prime) to all numbers.<\/li>\n<li>Or, <em>\u00f8<\/em>(<em>n<\/em>) returns the number of integers less than <em>n<\/em> (including 1) that are relatively prime to <em>n<\/em>.<\/li>\n<\/ol>\n<p>Note: we say that two integers <em>a<\/em> and <em>b<\/em> are relatively prime if <em>a<\/em> and <em>b<\/em> have no common positive factor other than 1 or, if their greatest common divisor is 1. <em>a<\/em> is relatively prime to <em>b<\/em> if gcd(<em>a<\/em>, <em>b<\/em>) = 1.<\/p>\n<p>A list of Euler&#8217;s Totient Function Values For n = 1 to 500, with divisor lists can be found in the following URL address: &lt;<a href=\"http:\/\/primefan.tripod.com\/Phi500.html\">http:\/\/primefan.tripod.com\/Phi500.html<\/a>&gt;<\/p>\n<p>For example:<\/p>\n<ol>\n<li>Lets n = 37 so <em>\u00f8<\/em>(<em>n<\/em>) = <em>\u00f8<\/em>(<em>37<\/em>) = 35. 37 can be divided by 1 and by 37.<br \/>\nTherefore, all integers from 1 to 36 are relatively prime to 37<\/li>\n<li>Lets n = 35 so <em>\u00f8<\/em>(<em>n<\/em>) = <em>\u00f8<\/em>(<em>35<\/em>) = 24. 35 can be divided by 1, 5, 7, and 35.<br \/>\nTherefore, integers 1, 2, 1, 2, 3, 4, 6, 8, 9, 11, 12, 13, 16, 17, 18, 19, 22, 23, 24, 26,<br \/>\n27, 29, 31, 32, 33, 34 are relatively prime to 35.<\/li>\n<\/ol>\n<p>You may ask, I did you found these values (such as <em>\u00f8<\/em>(<em>35<\/em>) = 24)?<\/p>\n<p>To find these values:<\/p>\n<ol>\n<li>(Case 1) For <em>n<\/em> = <em>p<\/em> (a prime), we have that <em>\u00f8<\/em>(<em>p<\/em>) = <em>p<\/em> &#8211; 1.<br \/>\nFor Example: Lets <em>p<\/em> = 7 so <em>\u00f8<\/em><em> <\/em>(<em>p<\/em>) = <em>\u00f8<\/em>(<em>7<\/em>), then <em>\u00f8<\/em><em> <\/em>(<em><em>7<\/em><\/em>) = <em>7<\/em> &#8211; 1 = 6.<br \/>\nTherefore <em>\u00f8<\/em>(<em><em>7<\/em><\/em>) = 6<\/li>\n<li>(Case 2) When <em>n<\/em> = <em>p^a<\/em> (power of a prime).<br \/>\nThe numbers with common factor with n are: <em>p, 2p, 3p, . . . ,p^(a-1) * p<\/em><br \/>\nsince there are<em> p^(a-1)<\/em> of them.<br \/>\nFor example: Lets assume we have a prime number <em>p<\/em> = 5 and <em>a<\/em> is 2:<em><br \/>\n<\/em><em>\u00f8<\/em>(<em>p^a<\/em>) = <em>p^a &#8211; p^(a-1)<\/em> = (<em>p<\/em>^(<em>a<\/em>-1)) * (<em>p<\/em> &#8211; 1) = (<em>p^a<\/em>) * (1 &#8211; 1\/<em>p<\/em>)<em><br \/>\n<\/em><em>\u00f8<\/em>(5^2) = 5^2 &#8211; 5^(2 -1) = (5^(2 &#8211; 1)) * (5 &#8211; 1) = (5^2) * (1 &#8211; 1\/5)<em><br \/>\n<\/em><em>\u00f8<\/em>(25) = 5^2 &#8211; 5 = 5 * (5 &#8211; 1) = (5^2) * (1 &#8211; 1\/5) = 20<br \/>\n<em>\u00f8<\/em>(25) = 20 and all integers relative prime to 25 are<br \/>\n1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24.<\/li>\n<\/ol>\n<p>As a general case for the Euler&#8217;t Totient function <em>\u00f8<\/em>(<em>n<\/em>), we have that:<\/p>\n<ol>\n<li>Let <em>p<\/em> be a prime integer dividing <em>n<\/em> integer so the integers divisible by <em>p<\/em> are:<br \/>\n<em>p, 2p, 3p, 4p, . . . , (n\/p)(p)<\/em> where there are <em>n\/p<\/em> number of integers.<\/li>\n<li>Then, the number of integers not divisible by <em>p<\/em> are: <em>n &#8211; n\/p = n * (1 &#8211; 1\/p)<\/em><\/li>\n<li>Let <em>q<\/em> be another prime number dividing <em>n<\/em>.<br \/>\nIf we wish to find the number of integers divisible by neither <em>p<\/em> or <em>q<\/em>,<br \/>\nthen deduct the <em>n\/q<\/em> multiples of <em>q<\/em> such that <em>q, 2q, 3q, . . . , (n\/q)(q)<\/em><\/li>\n<li>In case some elements of <em>p<\/em> and <em>q<\/em> are common, the <em>n\/pq<\/em> multiples of <em>pq<\/em> are:<br \/>\n<em>pq, 2pq, 3pq, . . . , (n\/pq)(pq)<\/em> so <em>n\/q &#8211; n\/pq = (n\/q)(1- 1\/p)<\/em><\/li>\n<li>Therefore the total of integers not divisible by <em>p<\/em> or <em>q<\/em> is:<br \/>\n<em>n(1 &#8211; 1\/p) &#8211; (n\/q)(1 &#8211; 1\/p) = n(1 &#8211; 1\/p)(1 &#8211; 1\/q)<\/em><\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">General formula for Euler&#8217;s Totient Function <em>\u00f8<\/em><\/span><span style=\"text-decoration: underline;\">(<em>n<\/em>)<\/span><span style=\"text-decoration: underline;\">:<br \/>\n<\/span><br \/>\n<em>\u00f8<\/em>(<em>n<\/em>) = <em>n * (1 &#8211; 1\/p1) * (1 &#8211; 1\/p2) * . . .\u00a0 * (1 &#8211; 1\/pm)<\/em>, where <em>p1, p2, . . . , pm<\/em> are prime factors of <em>n<\/em> and <em>m<\/em> is the total number of prime numbers.<\/p>\n<p>Example:<\/p>\n<p>Lets <em>n<\/em> = 60, <em>p1<\/em> = 2, <em>p2<\/em> = 4,\u00a0 <em>p3<\/em> = 5 and <em>\u00f8<\/em>(<em>n<\/em>)\u00a0 <em>= n * (1 &#8211; 1\/p1) * (1 &#8211; 1\/p2) * <\/em><em>(1 &#8211; 1\/p3)<em> then<\/em><br \/>\n<\/em><\/p>\n<p><em>\u00f8<\/em>(<em> <\/em>60) = 60 * (1 &#8211; 1\/2) * (1 &#8211; 1\/3) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (60 &#8211; 60\/2) * (1 &#8211; 1\/3) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (60 &#8211; 30) * (1 &#8211; 1\/3) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (30) * (1 &#8211; 1\/3) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (30 &#8211; 30\/3) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (30 &#8211; 10) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (20) * (1 &#8211; 1\/5)<br \/>\n<em>\u00f8<\/em>(60) = (20 &#8211; 20\/5)<br \/>\n<em>\u00f8<\/em>(60) = (20 &#8211; 4)<br \/>\n<em>\u00f8<\/em>(60) = 16<\/p>\n<p>All integers relative prime to 16 are:<br \/>\n1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59<\/p>\n<p><span style=\"text-decoration: underline;\">Euler&#8217;s Totient Function <em>\u00f8<\/em><\/span><span style=\"text-decoration: underline;\">(<em>n<\/em>)<\/span><span style=\"text-decoration: underline;\"> using two Prime Numbers:<\/span><\/p>\n<p>Let have two prime number <em>p<\/em> and <em>q<\/em> such that <em>p \u2260 q<\/em> so <em>\u00f8(pq) = \u00f8(p)*\u00f8(q) = (p-1)*(q-1) <\/em>in which<\/p>\n<ol>\n<li>The set {1, 2, &#8230;, <em>pq<\/em> -1} of integers is less than <em>pq<\/em><\/li>\n<li>The integers in the set {1, 2, &#8230;, <em>pq<\/em> &#8211; 1} are not relatively prime to <em>pq<\/em>:<br \/>\n{<em>p<\/em>, 2<em>p<\/em>, &#8230;, (<em>q<\/em> &#8211; 1)<em>p<\/em>} and {<em>q<\/em>, 2<em>q<\/em>, &#8230;, (<em>p<\/em> &#8211; 1)<em>q<\/em>}<\/li>\n<li><em>\u00f8(pq) = (pq &#8211; 1) \u2013 [(q-1) + (p-1)]<br \/>\n\u00f8(pq) = pq \u2013 p \u2013 q +1<br \/>\n\u00f8(pq) = (p-1) * (q-1)<br \/>\n\u00f8(pq) = \u00f8(p)*\u00f8(q)<br \/>\n<\/em><\/li>\n<\/ol>\n<p>For example:<\/p>\n<p><em>\u00f8(n)<\/em><em> = <\/em><em>\u00f8(pq) <\/em><em>= (p-1) * (q-1)<\/em><em> <\/em><br \/>\n<em>\u00f8(21) = <\/em><em>\u00f8(3 * 7) <\/em><em><br \/>\n<\/em><em>\u00f8(21) <\/em><em>= <\/em><em>(3 &#8211; 1) * (7 &#8211; 1)<br \/>\n<\/em><em>\u00f8(21) <\/em><em>= 2 * 6<br \/>\n<\/em><em>\u00f8(21) <\/em><em>= 12<\/em><\/p>\n<p>(&lt;<a href=\"http:\/\/home.earthlink.net\/%7Eusondermann\/eulertot.html\" target=\"_blank\">http:\/\/home.earthlink.net\/~usondermann\/eulertot.html<\/a>&gt;)<\/p>\n<p><strong>Euler&#8217;s Theorem<\/strong><\/p>\n<p>Euler&#8217;s Theorem (also known as Fermat-Euler theorem) establish that for every positive integer <em>a<\/em> relatively prime to <em>n<\/em> then <a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1415\" title=\"Screenshot-1\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-1.png\" alt=\"\" width=\"98\" height=\"16\" \/><\/a><\/p>\n<p>For example:<\/p>\n<ol>\n<li>Lets a = 3 and n = 10 then <em><br \/>\n<\/em><em>\u00f8(n)<\/em><em> = <\/em><em>\u00f8(pq) <\/em><em>= (p-1) * (q-1)<\/em><em><br \/>\n\u00f8(10)<\/em> = <em>\u00f8(2*5) = (2 &#8211; 1) * (5 -1) = (1) * (4<\/em>) = 4<em><br \/>\na<\/em>^<em>\u00f8(n) mod n = 1<\/em><em><br \/>\n<\/em><em>3<\/em>^<em>\u00f8(10) mod 10 = 1<br \/>\n<\/em><em>3<\/em>^<em>4 mod 10 = 1<\/em><br \/>\n<em>81<\/em><em> mod 10 = 1<\/em><\/li>\n<li>Lets a = 2 and n = 11 then <em><br \/>\n<\/em><em>\u00f8(n)<\/em><em> = <\/em><em>\u00f8(p &#8211; 1) <\/em><em><br \/>\n\u00f8(11)<\/em> = <em>\u00f8(11 &#8211; 1) = 10<\/em><em><br \/>\na<\/em>^<em>\u00f8(n) mod n = 1<\/em><em><br \/>\n2<\/em>^<em>\u00f8(11) mod 11 = 1<br \/>\n<\/em>2^<em>10 mod 11 = 1<\/em><br \/>\n<em>1024 mod 11 = 1<\/em><\/li>\n<\/ol>\n<p><strong>Primality Testing<\/strong><\/p>\n<ol>\n<li>Very large prime numbers selected at random are necessary for most of cryptographic algorithms.<\/li>\n<li>Na\u00efve Algorithm: The objective of this algorithm is to divide a number <em>a<\/em> by all the numbers in turn that are less than the square root of <em>a<\/em>. This kind of algorithm works for small numbers, but it inefficient for large numbers.<\/li>\n<\/ol>\n<p><strong>Miller Rabin Algorithm<\/strong><\/p>\n<p>Miller Rabin algorithm (also known as Miller-Rabin Primality Test) is an algorithm that return a true or false value depending a given value <em>n. <\/em>Normally, If it outputs true, then <em>n<\/em> is &#8220;probably prime&#8221;, else then <em>n<\/em> is definitely composite.<\/p>\n<p><span style=\"text-decoration: underline;\">Approach 1:<\/span><\/p>\n<p>[Split Off Power of]: Lets <em>n<\/em> &gt; 3 and n be odd, <em>k<\/em> &gt; 0, and\u00a0 <em>q<\/em> odd so <a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1418\" title=\"Screenshot-3\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\" alt=\"\" width=\"60\" height=\"19\" \/><\/a><\/p>\n<ol>\n<li>[Random Base] Choose a random integer <em>a<\/em> with 1 &lt; <em>a<\/em> &lt; <em>n.<\/em><\/li>\n<li>[Odd Power] Set b = a^n (mod m) so if b = \u00b11 (mod n) then output true and terminate.<\/li>\n<li>[Even Powers] For any r with 1 &lt;= r &lt;= k &#8211; 1, if b^2^r = -1 (mod n) then output true and terminate else output false<\/li>\n<\/ol>\n<p>(&lt; <a href=\"http:\/\/modular.math.washington.edu\/edu\/2007\/spring\/ent\/ent-html\/node26.html\" target=\"_blank\">http:\/\/modular.math.washington.edu\/edu\/2007\/spring\/ent\/ent-html\/node26.html<\/a>&gt;)<span style=\"text-decoration: underline;\"><a href=\"http:\/\/modular.math.washington.edu\/edu\/2007\/spring\/ent\/ent-html\/node26.html\"><br \/>\n<\/a><\/span><\/p>\n<p><span style=\"text-decoration: underline;\">Approach 2:<\/span><\/p>\n<ol>\n<li>Lets <em>n<\/em> &gt; 3 and n be odd, <em>k<\/em> &gt; 0, and\u00a0 <em>q<\/em> odd so <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-3\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\" alt=\"\" width=\"60\" height=\"19\" \/><\/a>.<br \/>\nDivide <em>(n &#8211; 1)<\/em> by 2 until the result is an odd number.<\/li>\n<li>Let a be an integer 1 &lt; a &lt; n where n &gt; 2 so <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\"><\/a><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1418\" title=\"Screenshot-3\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\" alt=\"\" width=\"60\" height=\"19\" \/><\/a><br \/>\nCheck which of the following two conditions is true:<br \/>\n(a) (<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1419\" title=\"Screenshot-4\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-4.png\" alt=\"\" width=\"85\" height=\"13\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-4.png 156w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-4-150x24.png 150w\" sizes=\"auto, (max-width: 85px) 100vw, 85px\" \/><\/a> ) == true ?<br \/>\n(b) There exist 1 &lt;= j &lt;= k such that <a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1420\" title=\"Screenshot-5\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-5.png\" alt=\"\" width=\"114\" height=\"18\" \/><\/a> == true ?<\/li>\n<li>If any of the previous conditions (a and b) are true, then n may not be a prime number.<\/li>\n<\/ol>\n<p>Example:<\/p>\n<ol>\n<li>Lets n = 2047 such that 2047 = 23 * 89.<\/li>\n<li>If <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-3\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\" alt=\"\" width=\"60\" height=\"19\" \/><\/a> so n &#8211; 1 = 2^1 * 1023 then<\/li>\n<li>2^1023 mod 2047 = 1<\/li>\n<li>However, 2047 is not a prime<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Approach 3:<\/span> (Similar to approach 1)<\/p>\n<ol>\n<li>Check if n integer value is prime or not<\/li>\n<li>If n is prime then find integers k &gt; 0, q being odd, such that <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-3\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-3.png\" alt=\"\" width=\"60\" height=\"19\" \/><\/a> is true.<\/li>\n<li>if <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-4.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-4\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-4.png\" alt=\"\" width=\"85\" height=\"13\" \/><\/a> is true then output is true (n maybe prime) else<\/li>\n<li>Check for every value of j going from 1 to k if <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-5.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-5\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-5.png\" alt=\"\" width=\"114\" height=\"18\" \/><\/a> is true.<br \/>\nIf true then output true (n maybe prime) else<\/li>\n<li>return false (n is not prime)<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Probabilistic Consideration<\/span><\/p>\n<p>For an odd no prime number <em>n<\/em> and a randomly chosen integer <em>a<\/em> where 1 &lt; <em>a<\/em> &lt; <em>n<\/em> -1,<br \/>\nwe can expect a probability of failure in detecting\u00a0 that n is not a prime number of less than one quarter of the probabiblities.<\/p>\n<p>If we repeat the Millan Rabin algorithm with different values of <em>a<\/em>, there is a chance that we find a &#8220;maybe&#8221; prime number <em>n<\/em> after trying a <em>t<\/em> number of tests:<\/p>\n<p>Probabilities of finding a &#8220;maybe&#8221; prime number <em>n<\/em> after <em>t<\/em> test are:<br \/>\nPr(<em>n<\/em> maybe a prime number after <em>t<\/em> tests) = (1\/4)^<em>t<\/em><\/p>\n<p>For example:<br \/>\nLets assume we wish perform <em>t<\/em> = 10 tests using different values of <em>a<\/em>, we have less than 10^-6 probabilities to find an <em>n<\/em> that maybe a prime number.<\/p>\n<p><strong>Extra Examples<br \/>\n<\/strong><\/p>\n<p>Lets have a = b mod p such that we wish to know a, b = 5^6 and p is 23 so a = 5^6 mod 23<\/p>\n<p>How can we solve this? Using Modulus Arithmetic. One of the properties say that C^(ab) mod p = (C^a mod p)^b mod p<\/p>\n<p>So,<\/p>\n<p>5^6 mod 23 =&gt; 5^(2*3) mod 23 =&gt; (5^2 mod 23)^3 mod 23 =&gt; (25 mod 23)^3 mod 23<\/p>\n<p>The remaider of 25 mod 23 is 2 (23 = 0, 24 = 1, 25 = 2) or you could divide 25 by 23: 23 * 1 = 23 =&gt; 25 &#8211; 23\u00a0 = 2 remainer<\/p>\n<p>(25 mod 23)^3 mod 23 =&gt; (2)^3 mod 23 =&gt; 8 mod 23 = 8 (is less than 23 so is inside the modulus)<\/p>\n\n<script>\nvar zbPregResult = '0';\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>NOTIFICATION: These examples are provided for educational purposes. The use of this code and\/or information is under your own responsibility and risk. The information and\/or code is given \u2018as is\u2019. I do not take responsibilities of how they are used. You are welcome to point out any mistakes in my posting and\/or leave a comment. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,264],"tags":[42,432,436,441,426,256,425,424,429,431,433,265,423,430,440,434,88,439,266,435,438,437],"class_list":["post-1400","post","type-post","status-publish","format-standard","hentry","category-programming","category-network-security","tag-algorithm","tag-arithmetic","tag-euler","tag-even","tag-fermats-theorem","tag-function","tag-gcd","tag-greates-common-divisor","tag-miller-rabin","tag-modulus","tag-naive","tag-network","tag-number","tag-number-theory","tag-odd","tag-primality","tag-prime","tag-probability","tag-security","tag-testing","tag-theorem","tag-torient"],"_links":{"self":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1400"}],"version-history":[{"count":21,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1400\/revisions"}],"predecessor-version":[{"id":1404,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1400\/revisions\/1404"}],"wp:attachment":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1400"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}