The RSA Algorithm

Understand the steps of the RSA algorithm, with an example explaining how to encrypt the message, send it over an unencrypted channel, and decrypt the message at the receiver’s end.

With that bit of number theory under our belts, we are ready to tackle the RSA algorithm. Here is how it goes. Bob wants to send me an encrypted message. The RSA algorithm has the following steps.

  1. I create a large number NN by multiplying together two fairly large prime numbers pp and qq; so N=pqN = pq.

  2. I also create an encryption key KK with K<NK < N and check that KK has no common factors (other than 11) with (p1)(q1)(p − 1)(q − 1). I send the integers KK and NN to Bob. I may use an unencrypted channel to do so.

  3. Let’s assume that Bob expresses his message as a number mm. Using the values of KK and NN I have sent him, Bob calculates another number cc such that c=mKmodNc = m^K \mod N and sends the number cc to me.

  4. In the meantime, I have calculated an integer dd such that

1=Kdmod(p1)(q1),1 = Kd \bmod (p − 1)(q − 1),

which means that (p1)(q1)(p − 1)(q − 1) divides Kd1K d − 1 evenly, that is, with no remainder. I need the two prime numbers pp and qq to calculate dd.

  1. To decode the message from Bob, I solve m=cdmodNm = c^d \bmod N.

Get hands-on with 1400+ tech skills courses.