0% found this document useful (0 votes)
16 views

RSA examples (2)

The document explains the RSA encryption and decryption process, detailing how to generate public and private keys, encrypt messages, and decrypt ciphertext. It provides several examples illustrating the calculations involved in encryption and decryption, including the use of modular arithmetic and the Euclidean algorithm. Additionally, it outlines the steps for converting plaintext to numerical form and back, emphasizing the importance of keeping certain key information secret.

Uploaded by

kashishj405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

RSA examples (2)

The document explains the RSA encryption and decryption process, detailing how to generate public and private keys, encrypt messages, and decrypt ciphertext. It provides several examples illustrating the calculations involved in encryption and decryption, including the use of modular arithmetic and the Euclidean algorithm. Additionally, it outlines the steps for converting plaintext to numerical form and back, emphasizing the importance of keeping certain key information secret.

Uploaded by

kashishj405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Questions

1. Callie wants to send the message M = 13 to Alice. Using Alice’s public


and private keys, calculate the ciphertext C, and the value for R when
Alice recovers the message.

Solution :

1. Callie encrypts message M = 13:

• Alice’s public key is (n, e) = (33, 3).

C=Me mod n = (13)3 mod 33 = 2197 mod 33 = 19

C = 19.

• Callie sends to Alice ciphertext C = 19.

Alice receives and decrypts ciphertext C = 19:

• Alice uses her private key (n, d) = (33, 7).

• When M = 197 mod 33

How to calculate 197

(19)1 = 19 mod 33 = 19

(19)2 = 192 mod 33= 361 mod 33 = 31

(19)4 = 312 mod 33 = 961 mod 33 = 4

(19)8 = 42 mod 33 = 16 mod 33 = 16

BINARY OF 7 = 0111

197 mod 33 = 19 X 31 X 4 MOD 33

= 2356 MOD 33 = 13

the remainder is R = 13.

• R = 13 = M, the original message from Callie!


Example 2 : Dexter wants to set up his own public and private keys.

He chooses p = 23 and q = 19 with e = 283.Find d so that ed has a remainder of 1


when divided by (p − 1)(q − 1).

Solution :

With p = 23, q = 19, we have m = (p − 1)(q − 1) = 22 x 18 = 396.

We want to find d so that ed = 283d has a remainder of 1 when divided by m =


396.

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.

We see that d = 7 works; that is ed = 283 × 7 = 1981 leaves a remainder of 1


when divided by 396.

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 :

• p = 11, q = 7, n = 77,  (n) = 60

• d = 13, e = 37 (ed = 481; ed mod 60 = 1)

• Let M = 15. Then C  Me mod n

– C  1537 (mod 77) = 71

• M  Cd mod n

– M  7113 (mod 77) = 15

Example 5 :

1. Let p = 7 and q = 13 be the two primes.

2. n = pq = 91 and φ = (p − 1)(q − 1) = 72.

3. Choose e. Let’s look among the primes.

• Try e = 2. gcd(2,72) = 2 (does not work)

• Try e = 3. gcd(3,72) = 3 (does not work)

• Try e = 5. gcd(5,72) = 1 (it works)


We choose e = 5.

Example :

Creating a Public and Private Key

 R andomly choose two LAR GE distinct primes p and q.


 Le t m=pq
 C alculate ϕ(m)=(p−1)(q−1)
 C hoose an integer e such that ( e,ϕ(m))=1
 Find an integer d which satisfies ed≡1modϕ(m)

Your public key will be the ordered pair ( e,m),


while your private key is the ordere d pair ( d,m).

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.

Le ts look at an e xample, say our plaintext is

message: NUMBER _THEO RY

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

The En c r yp tion Alg or ithm


 C onvert plaintext into its numerical equivalent, as shown previously
 R e call the public k ey you are using is ( e,m)
 Se parate these numbers into blocks, which are viewe d as a single number, and label them P1 , P_2, ..., P_k$,
m ak ing sure that for e ach 1≤i≤k that Pi <m.
 For e ach 1≤i≤k, compute (Pi )emodm and label the re sult C i
 The re sulting blocks C1,C2,...,Ck are your new cipher te xt.

You can now transmit C1 ,C2 ,...,Ck

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,

which give s m=(31)(37)=1147.

ϕ(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.

Jack 's secre t message to C hloe states,

message: W E_LO VE_MATH

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

So his ciphertext becomes,

ciphertext: 611 1145 851 510 96 246 1 405

And Jack sends "611 1145 851 510 96 246 1 405" to Chloe.

The Dec r yp tion Alg or ithm

 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.

Your m essage should now be comprehensible.

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.

 C hloe (and ONLY C hloe) k nows m =1147=(31)(37), so ϕ(1147)=1080


 R e call she uses e=17
 The next step is solving for d , which is the multiplicative inverse of e mod1080

So Chloe k nows he r private key is (953, 1147).

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,

ciphertext: 1 41 203 744 472 947 423 968 718

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

resulting #'s: 1 324 261 620 41 819 81 413 180


So the re sulting numbers should be the plaintext in number form. Since C hloe knows that Jack used a block size of 3,
she k nows to add e xtra zeros to P1=1, P5 =41, and P7=81. So P1 becomes 001, P5 becomes 041, and P7 becomes
081. So C hloe has the plaintext:

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,

message: ANY_Q UESTIONS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy