Home » Tutorials » When prime numbers are one after another…

# When prime numbers are one after another…

Today, different software use semiprime numbers to encrypt your message or data in general. A semiprime number consists in a product of two large prime numbers. This idea is used because large semiprime numbers are very hard to factorize.

In cryptography, there are different ways to factorize a semiprime number, from the high-school 1 to sqrt(n) algorithm to general number field sieve. But, there is also an algorithm to factorize the semiprime number easily if the prime numbers are one after another or close.

Let’s name the two prime numbers p and q and the semiprime number m. So, we get the following equation:

 1 p * q = m

We also know Goldbach’s Conjecture that states that the result of any two prime numbers added together is an even number which we will call 2n. So…

 1 p + q = 2n

When adding this two equations together and removing q, we will come up with:

 1 p^2 - 2pn + m = 0

Solving the equation will reveal:

 12 p = n - sqrt(n^2 - m) q = n + sqrt(n^2 - m)

This two equations are really interesting because:
• p and q are integers
• sqrt(n^2 – m) must be an integer number, so (n^2 – N) must be a perfect square

To start cracking, we will calculate n as ceiling(sqrt(m)) and increment it until n^2 – m is a perfect square.

The algorithm for this method is the following:

 12345678910111213141516171819202122232425262728293031