Lab7 F
Lab7 F
function g=gcd(a, b)
while b <> 0 do
temp = b;
b = modulo(a, b);
a = temp;
end
g = a;
endfunction
for d = 1:phi_n
return
end
end
endfunction
result = 1;
if modulo(exp, 2) == 1 then
end
end
endfunction
// Function to generate RSA keys
n = p * q;
phi_n = (p - 1) * (q - 1);
e = 2;
e = e + 1;
end
d = modInverse(e, phi_n);
endfunction
function C=encrypt(M, e, n)
C = modExp(M, e, n);
endfunction
function M=decrypt(C, d, n)
M = modExp(C, d, n);
endfunction
p = 61;
q = 53;
C = encrypt(M, e, n);
OUTPUT :
CONCLUSIONS :
The C program successfully implements RSA encryption and decryption, demonstrating the
fundamental operations of key generation, encryption, and decryption. The encryption and
decryption processes correctly transform a message into an encrypted form and back to its original
value. This example highlights the practical application of RSA for secure message transmission.