<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" [ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>RSA</title>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="../../comsci/css/s011.css" />
<link rel='SHORTCUT ICON' href='../../comsci/images/FrameHome.ico' />
</head>

<body>

<div class="message_right">
  <a href="http://validator.w3.org/check/referer">
    <img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid
	XHTML 1.1!" height="31" width="88" />
  </a>
  <a href="http://jigsaw.w3.org/css-validator/">
    <img style="width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
  </a>
  <br />
  Created 2004-12-15 &nbsp; Modified 
<!--UPDATE_DATE_BEGIN-->
2009-04-11<br />
<a class="reflocal" href="../../doc02.html">Chelton Evans</a>

<!--UPDATE_DATE_END-->
</div>

<h1> 
<a href="number.xml">
<img alt="Number Theory" src="../../comsci/images/number.png" />
</a>
RSA
<a href="../../../index.html">
  <img alt="home" src="../../comsci/images/Frame.gif" /> </a>
</h1>

<p>
<a class="reflocal2" href="#Intro">Intro</a><br />
<a class="reflocal2" href="#RSA_Algorithm">RSA Algorithm</a><br />
<a class="reflocal2" href="#Generating_Primes">Generating Primes </a><br />
<a class="reflocal2" href="#Euler_s_Power_Law_for_mod_Arithmetic">
  Euler's Power Law for mod Arithmetic</a><br />
<a class="reflocal2" href="#Unique_Public_Exponent">
  Unique Public Exponent</a><br />
</p>

<div class="float25">

<a id="Intro"></a>
<h2> Intro </h2>

<p> Brackets with a subscript is the mod function.
 See <a class="reflocal" href="n028.xml"> mod Arithmetic </a>.
</p>

<p> This is intended to be a mathematical perspective of RSA.
 The following shows how RSA works. For example there is
 no need to explicitly apply the Euler's totient function
 mod because it is part of the number system and for
 the correct choice of numbers happens automatically.
</p>

<p> See <a class="reflocal" href="../../misc/proj/rsa/doc.html"> proj/rsa </a> for a
 RSA implementation in C++. </p>

<p>
Without M.Schroeder's "Number Theory in Science and 
 Communication"'s 5 page explanation I would not be
 as informed. This was a really enjoyable read.
</p>

<hr />

</div>
<div class="float25">

<a id="RSA_Algorithm"></a>
<h2> RSA Algorithm </h2>

<p class="equ">
<math xmlns="&mathml;">
  <mi>m</mi>
</math>
 &nbsp; is the message. <br />
<math xmlns="&mathml;">
  <mi>c</mi>
</math>
 &nbsp; is the cipher. <br />
<math xmlns="&mathml;">
  <mi>E</mi>
</math>
 &nbsp; is to encrypt. <br />
<math xmlns="&mathml;">
  <mi>D</mi>
</math>
 &nbsp; is to decrypt. <br />

</p>



<p class="equ">
  E: &nbsp; &nbsp; 
<math xmlns="&mathml;">
  <mi>c</mi>
  <mo>=</mo>
  <mo>(</mo>
  <mi>m</mi>
  <msup>
    <mi></mi>
    <mrow><mi>e</mi></mrow>
  </msup>  
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
</math>
</p>

<p class="equ">
 D: &nbsp; &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>c</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>

    </mrow>
  </msup> 
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mo>(</mo>
  <mo>(</mo>
  <mi>m</mi>
  <msup>
    <mi></mi>
    <mrow>

<mi>e</mi>

    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>)</mo>
  <msup>
    <mi></mi>
    <mrow>

  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>

    </mrow>
  </msup> 

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

</math>

<br />
 &nbsp; 
 &nbsp; 
 &nbsp; 
 &nbsp; 
 &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>c</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>

    </mrow>
  </msup> 
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>

  <mo>(</mo>
  <mi>m</mi>
  <msup>
    <mi></mi>
    <mrow>


  <mo>(</mo>
  <mi>e</mi>
  <mo>.</mo>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>

    </mrow>
  </msup> 

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>



</math>

</p>

<p class="equ">
<math xmlns="&mathml;">
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
</math>
 &nbsp; 
 chosen: &nbsp; &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>e</mi>
  <mo>.</mo>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>
  <mo>=</mo>
  <mi>1</mi>


</math>
</p>

<p class="equ">
 &nbsp; 
 &nbsp; 
 &nbsp; 
 &nbsp; 
 &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>c</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>

    </mrow>
  </msup> 
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>

  <mo>(</mo>
  <mi>m</mi>
  <msup>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>m</mi>
</math>

</p>



<p class="equ">
This works when &nbsp; 
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>m</mi>
  <mo>,</mo>
  <mi>n</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>1</mi>
</math>


</p>

</div>
<div class="float25">

<p>
The RAS Algorithm works for n being prime but the inverse
 is easily calculated. It gets its security from
 n being the product of two primes. Euler's totient
 function is easily found in this case if you know
 the primes. But if you do not know the 
 primes you need to factor n. For really large
 n this is extremely difficult, the larger the
 primes the more difficult the task becomes.
</p>

<p class="equ">
<math xmlns="&mathml;">
  <mi>p</mi>
  <mo>,</mo>
  <mi>q</mi>
</math>
 &nbsp; are prime. <br />

<math xmlns="&mathml;">
  <mi>n</mi>
  <mo>=</mo>
  <mi>p</mi>
  <mi>q</mi>
</math>
<br />
<math xmlns="&mathml;">
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

  <mo>=</mo>
  <mo>(</mo><mi>p</mi><mo>-</mo><mi>1</mi><mo>)</mo>
  <mo>(</mo><mi>q</mi><mo>-</mo><mi>1</mi><mo>)</mo>

</math>

</p>

<hr />

</div>
<div class="float25">

<a id="Generating_Primes"></a>
<h2> Generating Primes </h2>

<p>
This is incredibly easy. 
 The tests are statistical in nature. Choose a number
 at random and if it satisfies Euler's totient function
 then p could be prime. Keep repeating this test
 for increasing confidence. One failure of the test
 means that p is not prime.

</p>

<p class="equ">
<math xmlns="&mathml;">
  <mi>r</mi>
</math> &nbsp; is a random number. <br />
<math xmlns="&mathml;">
  <mi>p</mi>
</math> &nbsp; is possibly a prime number. <br />
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>r</mi>
  <msup>
    <mi></mi>
    <mrow><mi>p</mi><mo>-</mo><mi>1</mi></mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>p</mi></mrow>
  </msub>
  <mo>==</mo>
  <mi>1</mi>
</math>


</p>

<p> However maths libraries often have prime testing
 functions that are probably more efficient.
 I also have a table of the first few hundred primes to 
 remove about 80% of non-prime numbers
 generated when searching for primes.
</p>

<p>
Generating random numbers of large sizes is generating
 n-bits and setting the leading bit. You could sequentially
 search for the next prime or randomly choose another number.
</p>

<hr />

</div>
<div class="float25">

<a id="Unique_Public_Exponent"></a>
<h2> Unique Public Exponent </h2>

<p> Do not have multiple public exponents. If a message
 is encrypted with multiple exponents it may be decrypted
 without knowing the key.
</p>

<p class="equ">
<math xmlns="&mathml;">
  <mi>c</mi>
  <msub>
    <mi></mi>

    <mrow><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mi>m</mi>
  <msup>
    <mi></mi>

    <mrow>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
</math>

<br />

<math xmlns="&mathml;">

  <mi>c</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>

  <mi>m</mi>
  <msup>
    <mi></mi>
    <mrow>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>

  </msub>
    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

</math>

<br />
Solve &nbsp; 

<math xmlns="&mathml;">
  <mi>a</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>

  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>a</mi>

  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>

  </msub>
  <mo>=</mo>
  <mi>1</mi>
</math>


<br />

<math xmlns="&mathml;">
  <mi>c</mi>

  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
  <msup>
    <mi></mi>
    <mrow>
  <mi>a</mi>

  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
    </mrow>
  </msup>

  <mi>c</mi>

  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
  <msup>
    <mi></mi>
    <mrow>
  <mi>a</mi>

  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
    </mrow>
  </msup>

  <mo>=</mo>

  <mo>(</mo>
  <mi>m</mi>
  <msup>
    <mi></mi>
    <mrow>
  <mi>e</mi>
  <msub>

    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
  <mi>a</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>

  </msub>
  <mo>+</mo>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>

  <mi>a</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>


    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>m</mi>

</math>


</p>

<hr />

</div>
<div class="float25">

<a id="Euler_s_Power_Law_for_mod_Arithmetic"></a>
<h2> Euler's Power Law for mod Arithmetic </h2>

<p> I made up the name as it seems appropriate. </p>

<p class="equ">
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow><mi>a</mi><mi>b</mi></mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mo>(</mo>
  <mi>a</mi>
  <mi>b</mi>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>

    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

</math>

<br />
 when &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <mo>,</mo>
  <mi>n</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>1</mi>
</math>

</p>

<p> The following is a proof of Euler's Power Law 
 for mod Arithmetic. </p>

<p class="equ">
Let &nbsp; 

<math xmlns="&mathml;">
  <mi>a</mi>
  <mo>.</mo>
  <mi>b</mi>
  <mo>=</mo>
  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
  <mo>+</mo>
  <mo>(</mo>
  <mi>a</mi>
  <mi>b</mi>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>
</math> <br />

 &nbsp; 
 &nbsp; 
 &nbsp; 
 &nbsp; 

<math xmlns="&mathml;">
  <mi>k</mi>
  <mo>&Element;</mo>
  <mi>J</mi>
</math> <br />

</p>

<p> Consider the left hand side. </p>

<p class="equ">
lhs: <br />
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow><mi>a</mi><mi>b</mi></mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
  <mo>+</mo>
  <mo>(</mo>
  <mi>a</mi>
  <mi>b</mi>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>
  
    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

</math>

<br />
  
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow><mi>a</mi><mi>b</mi></mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>


  <mo>.</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mo>(</mo>
  <mi>a</mi>
  <mi>b</mi>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>
  
    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

</math>


<br />
  
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow><mi>a</mi><mi>b</mi></mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

  <mo>.</mo>

  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mo>(</mo>
  <mi>a</mi>
  <mi>b</mi>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow>
<mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>
    </mrow>
  </msub>
  
    </mrow>
  </msup>

  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

</math>


</p>

<p class="equ">

 If &nbsp; 
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>1</mi>
</math>

 &nbsp; then the left hand
 side is equal to the right hand side.

</p>

<p class="equ">

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mo>(</mo>
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>)</mo>
  <msup>
    <mi></mi>
    <mrow>
      <mi>k</mi>
    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  

</math>

<br />
 But &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>1</mi>
</math>
 &nbsp; when &nbsp; 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <mo>,</mo>
  <mi>n</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>1</mi>
</math>

<br />

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>x</mi>
  <msup>
    <mi></mi>
    <mrow>

  <mi>k</mi>
  <mi>&straightphi;</mi><mo>(</mo><mi>n</mi><mo>)</mo>

    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>(</mo>
  <mi>1</mi>
  <msup>
    <mi></mi>
    <mrow>
      <mi>k</mi>
    </mrow>
  </msup>
  <mo>)</mo>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>1</mi>
</math>

</p>

<hr />

</div>

</body>
</html>


