RSA Algorithm
RSA Algorithm
P=7 , Q=17
N = P * Q
N = 7 * 17
N = 119
Step 3:
3. Select the public key (i.e. Encryption Key) E such that it is not a factor
of (P-1) and (Q-1) i.e. (relatively prime to Φ(N) and less than Φ(N)
• After some calculations , Let us take D=77, Then the following is true
• (77*5) mod 96 =385 mod 96 =1 (which is what we wanted)
Step 5:
5. For Encryption, Calculate the cypher text CT from the plain text PT
CT=PTE mod N
P=17, Q=11
N = P * Q
N = 17 * 11
N = 187
Step 3:
3. Select the public key (i.e. Encryption Key) E such that it is not a factor
of (P-1) and (Q-1) i.e. (relatively prime to Φ(N) and less than Φ(N)
• After some calculations , Let us take D=23, Then the following is true
• (23*7) mod 160 =161 mod 160 =1 (which is what we wanted)
Step 5:
5. For Encryption, Calculate the cypher text CT from the plain text PT
CT=PTE mod N
P=7, Q=11
N = P * Q
N = 7 * 11
N = 77
Step 3:
3. Select the public key (i.e. Encryption Key) E such that it is not a factor
of (P-1) * (Q-1) i.e. (relatively prime to Φ(N) and less than Φ(N)
Φ X +EY = gcd(Φ,E)
60 X +13 Y=gcd(60,13)
Y=D
Solve until d=1 (note d !=D, b=D)
i) calculate k2 iv) calculate d3=d1-(d2*k2)
a b d K
d1/d2= 60/13 =4
1 1 0 60 - d3=60-(13*4)
2 0 1 13 4 =60-(52)
ii) calculate a3=a1-(a2*k2)
3 1 -4 8 1 =1-(0* 4) =8
=1 v) calculate k3
iii) calculate b3=b1-(b2*k2) d2/d3= 13/8 =1
=0-(1* 4)
=-4
Solve until d=1 (note d !=D, b=D)
A=gX mod n
B=gY mod n
K1=BX mod n
Simple explanation
Step 6
K2=AY mod n
Simple explanation
Step 1
K1 = K2 = K = key
K becomes the secret key between
Alice & Bob
Example
• Alice & Bob Agree on two large prime numbers n and g
n = 11 and g= 7
Alice chooses another large random number X a
calculate A such that (Let X=3)
X
A=g mod n
3
A=7 mod 11
A=343 mod 11 A=2
Example
Bob chooses another large random number Y
and calculate B such that (Let Y=6)
Y
B=g mod n
6
B=7 mod 11
B=117649 mod 11 B=4
A=2 sent to Bob
K1=(gy)Xmod n
Mathematical Theory behind the algorithm
In Step 7
Bob computes secret key K2
K2=AY mod n
Bob computes secret key K2
If we substitute the value of A in step 7
A=gX mod n
K2 =(gX)Ymod n
K1=(gy)Xmod n K2 =(gX)Ymod n
K1=K2= k= 9
• The final symmetric key between Alice & Bob is made up
of three parts g, X and Y
• The first part of the Key i.e. g is a public number known
to everyone
• The other two parts of the key i.e. X and Y must be made
available by Alice and Bob
Man in the Middle attack
Man in the Middle attack
• Alice wants to communicate with Bob securely and therefore she
wants to do a Diffie Hellman key exchange with him
• She sends the value of n ang g to bob
Alice Bob
Calculates A Calculates B
Tom
Calculates A & B
Man in the Middle attack
Tom
Alice Bob
Calculates A & B
Calculates A Calculates B
A=gX mod n
A=gX mod n B=gY mod n
A=78 mod 11
A=73 mod 11 B=79 mod 11
A=5764801mod 11
A=343 mod 11 B=40353607mod 11
A=9
A=2 B=8
B=gY mod n
B=76 mod 11
B=117649 mod 11
B=4
Man in the Middle attack- Expected values
Alice Bob
Expects Tom Generated Expects
A=9 & B=4
A=2 & B=8 B=8 & A=2
Interference of Tom
Alice Bob
Received A=2 & B=8 Received
A=2 & B=4 B=8 & A=9
Man in the Middle attack Calculate Key
Tom
Alice Bob
Calculates K1 & K2
Calculates K1 Calculates K2
K1=BX mod n K2 =AY mod n
K1=BX mod n
K1 =88 mod 11 K2 =99 mod 11
K1 =43 mod 11
K1 =16777216mod 11 K2 =387420489mod 11
K1 =64 mod 11
K1 =5 K2 =5
K1 =9
K2 =AY mod n
K2 =26 mod 11
K2 =64 mod 11
K2 =9