title: Custom RSA implementation in Javascript (NodeJS)
body: <p>I've tried to implement the basics of RSA into a simple NodeJS / javascript file.  </p>
  
  <p>For encrypting I've used <code>c = m^e % n</code>.<br>
  For decrypting I've used <code>m = c^d % n</code>.</p>
  
  <pre><code>const p = 7; // choice prime
  const q = 13; // choice prime
  const n = p * q;
  const e = 5; // choice
  const Ke = [e, n]; // the private key
  const d = 29; // choice
  const Kd = [d, n]; // the public key
  
  let message = 'hello'
  let encrypted = []
  
  message = message.toUpperCase()
  
  for (let i = 0; i &lt; message.length; i++) {
    const char = message.charCodeAt(i) - 64 // m
    const pow = Math.pow(char, e) // m^e
    const mod = pow % n // mod n
    encrypted[i] = mod
  }
  
  encrypted.forEach(char =&gt; {
    const pow = Math.pow(char, d) // c^d
    const mod = pow % n // mod n
    console.log(String.fromCharCode(mod + 64))
  })
  </code></pre>
  
  <p>The encrypting goes well. However, the decrypting has some issues. It shows other characters then I've put in in the <code>let message = 'hello'</code> part  </p>
  
  <p>What am I doing wrong with decrypting?</p>