Develop a MATLAB program to encrypt and decrypt multimedia data using RSA. This includes…
- User
Develop a MATLAB program to encrypt and decrypt multimedia data using RSA. This includes 2 parts:
-
Creating encryption and decryption keys
-
Encrypting and decrypting messages
-
- Assistant
Part 1:
% Generating public and private keys using RSA clc; clear all; close all;
p = 61; % Declare two random prime numbers, p and q q = 53; n = pq; phi = (p-1)(q-1);
% Calculate e, the encryption key e = 3; while gcd(e,phi) ~= 1 e = e + 2; end
% Calculate d, the decryption key d = modinv(e,phi);
% Output public and private keys fprintf('Public key (e, n) = (%d, %d)\n', e, n); fprintf('Private key (d, n) = (%d, %d)\n', d, n);
% Function to calculate modular inverse function y = modinv(x, n) a = x; b = n; u = 1; v = 0; while b ~= 0 q = floor(a/b); r = a - qb; a = b; b = r; temp = u - qv; u = v; v = temp; end if u < 0 u = u + n; end y = u; end
Part 2:
% Encrypting and decrypting data using RSA clc; clear all; close all;