# Breaking Cryptography

In this article, we will discuss the overview of symmetric encryption protocols and how the need for Asymmetric Encryption came into the picture. Here we will discuss the overview, cryptography examples, and rules for breaking cryptography. Letâ€™s discuss them one by one.

**Overview : **

A key scrambles the messages and that very key can decrypt the messages. Then, Alice and Bob can exchange messages once they agree on a key. But how can they both agree on a secret key over a network that is monitored by eavesdroppers? Let’s assume that the eavesdropper is Eaves! Now, to resolve the problem we use the asymmetric key instead.

**Example –**

Alice encrypts her message with Bob’s public key because only Bob can decrypt the message with his very own private key. Similarly, Bob encrypts his message with the public key of Alice can only be decrypted by Alice’s private key. Now, Alice can also use this method to authenticate herself to Bob. She can encrypt her message with her private key and then encrypt that result with Bob’s public key. When Bob decrypts the message with his own private key, he sees that there already exists an inner layer of encryption. Now, if this can be encrypted with Alice’s public key then he’ll be sure that it was Alice who encrypted it.

**Generating a private key :**

Let’s now get into the essence of how these keys were generated in the first place as follows.

**Approach –**

- Generating a private key is computationally very difficult to produce. It simply cannot be produced by reverse-engineering the public key produced by an algorithm called the RSA algorithm.
- What is the protocol of the RSA algorithm?
- We produce a number(N) which is a product of two prime numbers(let’s say p and q)
- Now, the number produced is quite large (nearly a hundred to a thousand digits).

p âˆ—q = N

**Example –**

Let’s understand it by one simple example as follows.

**Step-1 :**

By using the above protocol let us define n using the multiplication of two prime numbers. (Taking a prime number directly can make the calculations complex.)

p=61, q =53. compute N. N = p*q N = 3233 Applying Euler's Totient function, âˆ…(n) = âˆ…(p*q) = âˆ…(p) * âˆ…(q) = (p-1)*(q-1) = 60*52 = 3120

**Step-2 :**

We didn’t take N directly because it would have become complex for us to compute a number of numbers that are co-prime to it.

Choose 'e' ; 1<=e<= âˆ…(n), co prime to âˆ…(n) Going by that, if we take e = 17 Then, Gcd(17,3120) should be = 1 (that means the numbers should be co-prime to each other.) our public key is :(e,N)= (17,3233)

**Step-3 :**

Now let’s determine the private key : (d, N)

e d = 1 mod âˆ…(n) here e and âˆ…(n) are co primes to each other Now going by the concept of Multiplicative Inverse we have, d = e^{-1}mod âˆ…(n) Finding d: d is calculated using the formula: = [(âˆ…(n) * i)+1]/e

**Step-4 :**

We keep on calculating it by changing the values of i. Here we took I as 1,2,3â€¦, etc. till we reach an answer where we get a non-decimal number.

at i = 15, we get d as 2753 hence our private key becomes: (d,N)=(2753,3233)

**Step-5 :**

After generating the public and private keys we perform encryption and decryption.

(m^{e)d}â‰¡ m mod N, where m - It is the message. Such computation is a one way function.

The strength of the RSA algorithm lies in N. The larger the number N, the slower it gets to take out its prime factors.

**Breaking Cryptography :**

Having discussed this, let’s get into how can we break cryptography!

- Cracking open secure systems would be easy if we knew how to factor in huge numbers.
- RSA uses these prime factors as keys to decrypt these messages. For that, we’ll need to find out the prime factors of a really huge number!
- Now, this can get quite boring and time-consuming.
- We’ll need to have a strategic plan to factor in them. Euler, a famous mathematician came to the rescue. He contemplated over prime numbers and
- It gave various postulates like modular arithmetic. Basically, he gave all the math under RSA cryptography.
- Modular Arithmetic:
- Here we consider the remainder when dividing two numbers.

a â‰¡ x mod N when we divide a/N, the remainder is --> x 2 Ã— 3 = 6 6/5 = 1 so, 2 Ã— 3 mod 5 is 1 its written as: 2*3 â‰¡ 1 mod 5

**Relation between exponentiation and modular arithmetic :**

Let’s look at the relation between exponentiation and modular arithmetic as follows.

Let’s understand with the help of examples.

- If we take powers of 3 (3
^{k}) we’ll get the numbers as 3,9.27,81,243 - Now, if we take the mod of the numbers with 10, we get a sequence as 9,7,1,3,9,7,1,3…so on.
- We observe that the sequence of power increases, but the modular cycle repeats itself.
- We also observe that the last digit of the pattern is always 1.
- Now, as long as x and N are co primes, x mod N, x
^{2 }mod N, x^{3}mod N â€¦ all of these will hold this property. - We call the length of the repeating pattern period.
- Here, the period of 3 mod 10 is 4 (as after every fourth digit the pattern repeats).
- The period is the smallest number ‘r’, such that,

x^{r}â‰¡ 1 mod N

**Calculating the factor of a number :**

Now let’s see how modular arithmetic, exponentiation, and period are related to calculating factors of the number.

Let’s say you are given a number N and you are also given its factors, p, and q. Nothing is known about p and q.

N = p .q

**Step-1 : **

Pick up any number smaller than N. Let’s call it ‘a’. Check whether a and N co primes. We check this by taking the GCD of both. GCD(a, N)=1, then they are co-prime to each other.

**Step-2 : **

The second step is to compute the period of a mod N. In this example, we take N = 32, and we assume a = 8 (since they both are co-prime to each other.) Let’s assume the period to be ‘r’.

powers of 8 = 8,64,512,4096..... mod 35 = 8,29,22,..1 We compute r to be as 4.

To make the arithmetic workout, we’ll need to divide r by 2. So, we need to know that r is even. Later, we’ll also need to know that a^{r/2} + 1 â‰‡ 0 mod N. If either of these things fails, we’ll need to pick a different ‘a’ in the starting step.

**Step-3 : **

For step 3, we have to do some algebra as follows. Let’s start with the things that we know.

a^{r}â‰¡ 1 mod N which on subtracting 1, gives a^{r}- 1 â‰¡ 0 mod N

Saying something as above is equivalent to saying that it is a multiple of N(since the remainder obtained here is 0.) So, there must exist some integer ‘k’ such that:

a^{r}- 1 = k .N Since we assumed 'r' as an even number here, we can write it as : (a^{r/2 }- 1 )(a^{r/2}+1 )= k. N Since N=p .q, so we replace N with p . q (a^{r/2}- 1 ) (a^{r/2}+1 ) = k. p .q Since, we have the period of 8 mod 35 as 4, we can write it as: 8^{4}â‰¡ 1 mod 35 so, 8^{4 }- 1 â‰¡ 0 mod 35 (its equivalent to saying that its a multiple of N) So we can re write it as: 8^{4 }- 1 = k . 35 rewriting this as (since r is even here): (8^{r/2 }- 1)(8^{r/2}+ 1) = k. p .q (where p .q are the prime factors of N)

**Step-4 : **

Now, step 4 is to calculate for p & q. We assume here that GCD((a^{r/2} – 1), N) is one of the prime factors. Let’s call it p. And, GCD((a^{r/2} + 1), N) is another prime factor. Let’s call it q. In equation (a^{r/2} – 1)(a^{r/2}+ 1) = k.p. q we make the assumption that p must divide one of the factors on the left side and q must also divide one of the factors on the left side. Both of them can’t divide the same factors on the left side since that factor would be divisible by N.

**Shor’s Algorithm :**

We make assumptions as follows.

p divides (a^{r/2 }- 1) and q divides (a^{r/2}+ 1) We get, p = Gcd(63,35) = 7 and q is the Gcd(65,35) = 5

Let’s have a quick recap of what we did as follows.

- Take ‘a’ less than N.
- Find the period of a mod N
- Rearrange with algebra
- Let p = Gcd ((a
^{r/2}– 1), N) and q = Gcd ((a^{r/2}+ 1), N)

And you are done! You have destroyed the security system. But we know that RSA still works and taking out the period takes a long time. But Here, comes the role of Quantum Computers. They are excellent at calculating the period. The above was the outline of Shor’s Algorithm.

## Please

Loginto comment...