Based on the fact that we don't have a P algorithm for integer factorization as of 2020. But nor proof that one does not exist!
The private key is made of two randomly generated prime numbers: and . How such large primes are found: how large primes are found for RSA.
The public key is made of:
  • n = p*q
  • a randomly chosen integer exponent between 1 and e_max = lcm(p -1, q -1), where lcm is the Least common multiple
Given a plaintext message m, the encrypted ciphertext version is:
c = m^e mod n
This operation is called modular exponentiation can be calculated efficiently with the Extended Euclidean algorithm.
The inverse operation of finding the private m from the public c, e and is however believed to be a hard problem without knowing the factors of n.
However, if we know the private p and q, we can solve the problem. As follows.
First we calculate the modular multiplicative inverse. TODO continue.
Answers suggest hat you basically pick a random large odd number, and add 2 to it until your selected primality test passes.
The prime number theorem tells us that the probability that a number between 1 and is a prime number is .
Therefore, for an N-bit integer, we only have to run the test N times on average to find a prime.
Since say, A 512-bit integer is already humongous and sufficiently large, we would only need to search 512 times on average even for such sizes, and therefore the procedure scales well.
As its name indicates, Diffie-Hellman key exchange is a key exchange algorithm. TODO verify: this means that in order to transmit a message, both parties must first send data to one another to reach a shared secret key. For RSA on the other hand, you can just take the public key of the other party and send encrypted data to them, the receiver does not need to send you any data at any point.