title: RSA Simple example with Javascript?
body: <p>I know this may be kind of basic but I am having an exam on the next week and I wanted to test my knowledge of RSA.</p>
  
  <p>I have a very simple problem that I am working on to see the mechanics of RSA, and I want to test if I can encrypt and decrypt a message in my browser console.</p>
  
  <p>The RSA variables are:</p>
  
  <pre><code>var p = 11 //the first prime number
  var q = 5 //the second prime number
  var m=72 // the message
  var n=55 // the RSA modulus, n = p*q
  var e=7 // so (e,n) are the public key
  var d=23 //so (d,n) are the private key
  var fi_of_n=40 //the totient, fi_of_n = (p-1)*(q-1) = 40
  </code></pre>
  
  <p>To encrypt, I am doing:</p>
  
  <pre><code>var c = Math.pow(m,e)%n // m^e mod(n); c=8
  </code></pre>
  
  <p>I get c to be equals to 8</p>
  
  <p>Then I want to decrypt, using d as follows:</p>
  
  <pre><code>var m2 = Math.pow(c,d)%n // c^d mod(n)
  </code></pre>
  
  <p>But the result is 17! not 72 as I expected. I don't know what I am doing wrong and I think it is a very simple example.</p>
  
  <p>The values of my public and private key are the ones obtained in this video: <a href="https://www.youtube.com/watch?v=kYasb426Yjk" rel="nofollow noreferrer">https://www.youtube.com/watch?v=kYasb426Yjk</a> <img src="https://i.stack.imgur.com/B0npv.png" alt="A screen capture of the RSA video I am getting the RSA variables from"></p>