RSA examples (2)
RSA examples (2)
Solution :
C = 19.
(19)1 = 19 mod 33 = 19
BINARY OF 7 = 0111
= 2356 MOD 33 = 13
Solution :
One way to do this is by simple trial and error, increasing the value of d until 283d
divided by 396 leaves a remainder of 1.
In general, trial and error could take a very long time, as the value of d could
be a big number. Instead, an ancient technique called Euclid’s Algorithm
can be used to find d in the linear Diophantine equation 283d + 396y = 1.
Example 3 :
Choose p = 3 and q = 11
Compute n = p * q = 3 * 11 = 33
Compute φ(n) = (p - 1) * (q - 1) = 2 * 10 = 20
Choose e such that 1 < e < φ(n) and e and n are coprime. Let e = 7
Compute a value for d such that (d * e) % φ(n) = 1.
One solution is d = 3 [(3 * 7) % 20 = 1]
Public key is (e, n) => (7, 33)
Private key is (d, n) => (3, 33)
The encryption of m = 2 is c = 27 % 33 = 29
The decryption of c = 29 is m = 293 % 33 = 2
Example 4 :
• M Cd mod n
Example 5 :
Example :
In orde r to avoid confusion with the Greatest C ommon Divisor function we will e x plicitly state whe n (#,#) is a
public/private k ey. It is important that the only information m ade public is your public k ey. This
m e ans p , q , ϕ(m) and d must be k ept secret because with any of this information, one could bre ak the code.
Encryption
S et Up
To be gin, we m ust associate e ach letter of the alphabet with a unique number. This will allow us to convert our
m e ssage into a series of numbers which we can then perform operations on. Let us use the following table for this,
Letter Number Letter Number
A 00 N 13
B 01 O 14
C 02 P 15
D 03 Q 16
E 04 R 17
F 05 S 18
G 06 T 19
H 07 U 20
I 08 V 21
J 09 W 22
K 10 X 23
L 11 Y 24
M 12 Z 25
"__" 26
Note that instead of letting A=0, we se t it equal to 00. This is because once we get up to K we start using double
digits. If we have a mix of single digits and double digits it would be impossible to convert back to our original
m e ssage. Also, it is useful to denote spaces in betwe e n words with a number. We will use an underscore betwe en
words inste ad of space to make it cleare r.
N U M B E R _ T H E O R Y
13 20 12 01 04 17 26 19 07 04 14 17 24
So we ge t,
plaintext: 13201201041726190704141724
E x am p l e o f t h e E n cryp ti o n A l gori t h m
Le ts say our old friend Chloe chose p=31, and q=37 for her prime numbers,
ϕ(m)=ϕ(1147)=(31−1)(37−1)=1080.
The n she must find an integer e which is re latively prime to 1080. She randomly selects e=17, and note
that (17,1080)=1. So C hloe publishes her public k ey of (17,1147).
Say Jack wants to send Chloe an e ncrypted message using R SA. All he knows is C hloe's public key (17,1147), so he
use s this in the encryption algorithm.
Afte r conve rting to numericals using the table above Jack has,
plaintext : 220426111421042612001907
He bre aks the numerical form of the message into blocks of 3 making sure e ach block is less than m .
plaintext in blocks: 220 426 111 421 042 612 001 907
So,
(1)
220=P1
426=P2
111=P3
421=P4
042=P5
612=P5
001=P7
907=P8
He the n computes for e ach Pi , from i=1 to i=8, Peimodm, with e =17, and m =1147 taken from C hloe's public k ey. And
the re sult is the cipherte xt
(2)
(220)17 mod1147
(426)17 mod1147
(111)17 mod1147
(421)17 mod1147
(042)17 mod1147
(612)17 mod1147
(001)17 mod1147
(907)17 mod1147
≡611≡1145≡851≡510≡96≡246≡1≡405
And Jack sends "611 1145 851 510 96 246 1 405" to Chloe.
Le t C1 ,C2 ,...,Ck be your ciphertext blocks, and ( d,m) be your private key
For e ach 1≤i≤k, compute (C i)d modm and the re sult will be Pi whe re 0≤Pi <m
The n, P1 ,P2,...,Pk is your plaintext in numerical form
Finally, convert the pairs of two -digit numbers back to its alphabetical e quivalent using our table.
E x am p l e o f t h e De cr ypt i on A l gori t hm
Again, re turning to our Jack and Chloe e xample, Jack was sending a m essage to Chloe using her public key. Now for
C hloe to decrypt a m essage sent to her, she must use her private key. We will re -use C hloe's key information in this
e x ample.
Now le ts se e how C hloe uses this info to decrypt a message. Say for e xample, Jack uses C hloe's public key and sends
he r another message using a block size of 3. This is what C hloe re cieves,
C hloe has all the information she needs to go through the decryption process to see what Jack sent her. Taking each
ciphe rte xt block C 1 =1,C 2=41,...,C 9 =560, and k nowing d=953, and m =1147, she computes C 953i mod1147. The
re sulting integers are the plaintext P1,P2 ,...,P9 . She gets,
(6)
1953 41953 203953744953 472953 947953 423953 968953 718953 mod1147≡1=P1 mod1147≡324=P2 mod1147≡261=P3 mod1147≡6
20=P4 mod1147≡41=P5 mod1147≡819=P6 mod1147≡81=P7 mod1147≡413=P8 mod1147≡180=P9
plaintext: 001 324 261 620 041 819 081 413 180
Finally she re groups into pairs of two so she can covert e ach pair back into its alphabetical equivalent.
00 13 24 26 16 20 04 18 19 08 14 13 18 0
A N Y _ Q U E S T I O N S
W hy is there a loner "0" at the e nd of out m essage, and how do we convert it back to alphabetical form? Since C hloe
k nows there is no letter of the alphabet paired up with the single digit "0" in their conversion table, she concludes this
e x tra "'0" must be a filler space. Jack simply added a meaningless bit of information to his plaintext in order to divide
the plaintext evenly into groups of thre e. It is important to see here that the original m essage did not divide e venly
into groups of three. If we try and do this, we will be left with the last block of "18", which cle arly is not 3 digits as
spe cified. So a filler space is needed, and "0" was randomly chosen to fill in. So finally, we have the message Jack sent
to C hloe is,