Skip to content
Related Articles

Related Articles

Improve Article

Breaking Cryptography

  • Last Updated : 26 May, 2021

In this article, we will discuss the overview of symmetric encryption protocols and 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 it one by one.

Overview : 
A key scrambles the messages and that very key can decrypt the message. 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 eavesdropper to be 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 were these keys generated in the first place as follows.

Approach –



  1. 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.
  2. What is the protocol of the RSA algorithm?
  3. We produce a number(N) which is a product of two prime numbers(let’s say p and q)
  4. Now, the number produced is quite large(near about hundreds 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 direct 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!



  1. Cracking open secure systems would be easy if we knew how to factor in huge numbers.
  2. 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!
  3. Now, this can get quite boring and time-consuming.
  4. 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
  5. It gave various postulates like modular arithmetic. Basically, he gave all the math under RSA cryptography.
  6. Modular Arithmetic:
  7. 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.

  1. If we take powers of 3 (3k) we’ll get the numbers as 3,9.27,81,243
  2. 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.
  3. We observe that the sequence of power increases, but the modular cycle repeats itself.
  4. We also observe that the last digit of the pattern is always 1.
  5. Now, as long as x and N are co primes, x mod N, x2 mod N, x3 mod N … all of these will hold this property.
  6. We call the length of the repeating pattern period.
  7. Here, the period of 3 mod 10 is 4 (as after every fourth digit the pattern repeats)
  8. The period is the smallest number ‘r’, such that,  
x r ≡ 1 mod N

Calculating 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 be needing to divide r by 2. So, we need to know that r is even. Later, we’ll also need to know that ar/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 thing that we know.

ar ≡ 1 mod N
which on subtracting 1, gives  
ar  - 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:

ar - 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:
84 ≡ 1 mod 35

so, 84 - 1 ≡ 0 mod 35 (its equivalent to saying that its a multiple of N)
So we can re write it as: 84 - 1 = k . 35
rewriting this as (since r is even here):

(8r/2 - 1)(8r/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((ar/2 – 1), N) is one of the prime factors. Let’s call it p. And, GCD((ar/2 + 1), N) is another prime factor. Let’s call it q. In equation (ar/2 – 1)(ar/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 (ar/2 - 1) and q divides (ar/2 + 1)
We get, p = Gcd(63,35) = 7
and q is the Gcd(65,35) = 5

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

  1. Take ‘a’ less than N.
  2. Find the period of a mod N
  3. Re-arrange with algebra
  4. Let p = Gcd ((ar/2– 1), N) and q = Gcd ((ar/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.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :