Professional Documents
Culture Documents
2017-CE-008 Lab 08
2017-CE-008 Lab 08
LAB#07
Public Key Cryptography – RSA Algorithm
OBJECTIVE
The purpose of this lab is to implement RSA Algorithm and use it for encryption and to
perform digital signature in MATLAB.
THEORY
Traditional private/secret/single key cryptography uses one key which is shared by both
sender and receiver. If this key is disclosed then communications are compromised. As a
result, another approach uses two keys – a public & a private key which is called
Asymmetric since parties use different keys and they are not equal. If one is encrypting
using a key, then the other cannot decrypt using the same key.
RSA:
Procedure:
d is nothing but the multiplicative inverse of e and vice versa in mod ø(n)
Publish their public encryption key: KU = {e,n}
Keep secret private decryption key: KR = {d,n}
To encrypt a message M the sender obtains public key of recipient KU={e,n}
e
Computes: C = M mod n, where 0≤M<n
To decrypt the ciphertext C the owner uses their private
d
key KR={d,n} Computes: M = C mod n
Note that the message M must be smaller than the modulus n
Matlab code:
The only primary operation here is modulo operation. Use mod command for
evaluating modulo of two numbers.
To generate random prime numbers, use the command primes(n).
To find primitive root of a number, use if statement and mod function.
Use gcd(a,b) command to verify whether e and d are relatively prime to ø(n)
To find the multiplicative inverse a number, use series of if statements and mod function.
Lab Tasks:
Perform the following tasks
1. Perform the block shown below such that RSA algorithm is used. Use the
following parameters to create the whole scenario.
User A: generates two prime numbers q = 3 and p = 5 and e = 7. The message M to be sent
by this user to user B is M = [0 1 1 0].
CODE:
clc
clear all
% User A
p = 5; q
= 3; n =
p*q; e =
7;
M=[0110];
Mdec = bin2dec(int2str(M));
C = mod(Mdec^e, n) % Encrypt
% User B
p = 3;
q = 7;
n = p*q;
e = 11;
D = mod(C^e, n) % Decrypt
OUTPUT:
CODE:
C = mod(20^80, 95)
OUTPUT: