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.
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.
The RSA variables are:
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
To encrypt, I am doing:
var c = Math.pow(m,e)%n // m^e mod(n); c=8
I get c to be equals to 8
Then I want to decrypt, using d as follows:
var m2 = Math.pow(c,d)%n // c^d mod(n)
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.
The values of my public and private key are the ones obtained in this video: https://www.youtube.com/watch?v=kYasb426Yjk