RSA
Contents
theory
- modular arithmetic
- Euler's theorem
- Euler's totient function
algorithm
- First, the receiver chooses two large prime numbers
pandq. Their product,n=pq, will be half of the public key. - The receiver calculates
ϕ(pq)=(p−1)(q−1)and chooses a numbererelatively prime toϕ(pq). In practice,eis often chosen to be2^16+1=65537, though it can be as small as 3 in some cases. ee will be the other half of the public key. - The receiver calculates (
exgcd) the modular inversedofemoduloϕ(n). In other words,de≡ 1 (mod ϕ(n)).dis the private key. - The receiver distributes both parts of the public key:
nande.dis kept secret.
application
- The public and private keys have been generated, they can be reused as often as wanted.
To transmit a message, follow these steps:
First, the sender converts his message into a number
m. One common conversion process uses the ASCII alphabet:A B C D E F G H I J K L M 65 66 67 68 69 70 71 72 73 74 75 76 77 N O P Q R S T U V W X Y Z 78 79 80 81 82 83 84 85 86 87 88 89 90 if
nis smaller than the message, it will be sent in pieces.- The sender then calculates
c ≡ m^e(mod n).cis the ciphertext, or the encrypted message. Besides the public key, this is the only information an attacker will be able to steal. - The receiver computes
c^d≡ m (mod n), thus retrieving the original numberm. - The receiver translates
mback into letters, retrieving the original message.