Given the following RSA keys, how does one go about determining what the values of p and q are?
Public Key: (10142789312725007, 5)
Private Key: (10142789312725007, 8114231289041741)
Given the following RSA keys, how does one go about determining what the values of p and q are?
Public Key: (10142789312725007, 5)
Private Key: (10142789312725007, 8114231289041741)
There are various fast algorithms to solve the problem of factoring
n
givenn
,e
, andd
. You can find a good description of one such algorithm in the Handbook of Applied Cryptography, Chapter 8, section 8.2.2. You can find these chapters online for free download here.Your teacher gave you:
which means
where n is the modulus and e is the public exponent.
In addition, you're given
meaning that
where d is the decryption exponent that should remain secret.
You can "break" RSA by knowing how to factor "n" into its "p" and "q" prime factors:
The easiest way is probably to check all odd numbers starting just below the square root of n:
You would get the first factor in 4 tries:
So we have
Now,
Why is this important? It's because d is a special number such that
We can verify this
This is important because if you have a plaintext message m then the ciphertext is
and you decrypt it by
For example, I can "encrypt" the message 123456789 using your teacher's public key:
This will give me the following ciphertext:
(Note that "e" should be much larger in practice because for small values of "m" you don't even exceed n)
Anyways, now we have "c" and can reverse it with "d"
Obviously, you can't compute "7487844069764171^8114231289041741" directly because it has 128,808,202,574,088,302 digits, so you must use the modular exponentiation trick.
In the "Real World", n is obviously much larger. If you'd like to see a real example of how HTTPS uses RSA under the covers with a 617-digit n and an e of 65537, see my blog post "The First Few Milliseconds of an HTTPS Connection."
The definition of RSA tells you that the modulus
n = pq
. You known
so you just need to find two numbersp
andq
that multiply to producen
. You know thatp
andq
are prime, so this is the prime factorisation problem.You can solve this by brute force for relatively small numbers but the overall security of RSA depends on the fact that this problem is intractable in general.
There is a lot of bad speculation about factorization of large semi primes which go into brute force or sieving neither of which is required to factorise the semi prime. 64 bit takes 1 - 2 seconds on my pc, and 256 bit generally less than 2 days
Here is a Java implementation of the fast factoring method from the Handbook of Applied Cryptography chapter 8 section 8.2.2 (thanks to GregS for finding it):
A typical output is
Here's a relatively simple way to look at it (and one that is doable by hand). If you were to factor the number completely, then the highest factor you would need to consider is sqrt(N):
The first prime below this is 100711409, just 6 below the sqrt(N).
therefore these are two factors of N. Your professor made it pretty easy - the trick is to recognize that no one would choose a small p or q so starting your check from the bottom (as in the python script someone posted) is a bad idea. If it's going to be practical by hand, the large p and q must lie near sqrt(N).