RSA algorithm:
1. Prepare two prime numbers pq
n = pq
2. Find the middle number L
l = the least common multiple (p-1, q-1) is 144
3. Seek E
1<E<L
greatest common divisor (e,l)=1
4. Seek D
1<D<L
E*D mol L = 1
practice
1. Prepare two very small pairs of prime numbers
p = 17
q = 19
N = p*q = 323
2. L = Least Common Multiple (of 16 and 18) is 144
3. 1<E<L greatest common divisor (E and L) = 1
ie 1 <E < 144 greatest common divisor (E, 144) = 1
take 5
Public key (E, N) = (5,323)
4. Find D 1<D<LE*DmodL = 1
that is 1<D<144 5*Dmod 144 = 1
Obviously when D=29,
1<29<144
5*29mod144 = 145mod 144 = 1 Then the
private key = (D,N) = (29,323)
5. The plaintext prepared for encryption must be a number less than N, because encryption or decryption requires mod N, and the result must be less than N.
Prepare plaintext = 123
, then ciphertext = plaintext EmodN=1235mod323=225
6. Decryption
Plaintext=ciphertext DmodN=22529mod323=123
The decrypted plaintext is 123.
Why is this algorithm so powerful:
If I give you the public key (E, N) as (5,323),
then you can encrypt and calculate the ciphertext of 225,
Then send me the ciphertext of 255.
How can I decrypt it if I don't have the private key?
The way to find D is:
1<D<L
E*D mol L = 1
I know E, N,
Below I need to know L
If you want to know L, you need to know p-1 and q-1 first
N is two prime numbers P*Q but what if I want to find p-1 and q-1 if this number is super large
Decomposition of large numbers is a mathematical problem in itself.