File Exchange

image thumbnail

RSA algorithm

version (1.47 KB) by suriyanath
RSA algorithm for encrypting and decrypting a message


Updated 17 Sep 2016

View License

This code asks for Two prime numbers and then computes Public and Private key. Then the message is encrypted using Public key and decrypted using Private key. An example is shown in figure.

Cite As

suriyanath (2020). RSA algorithm (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)


No funciona. same to me.
Error in rsa_code (line 15)
e=randi(1,1,[2 n1]);

No funciona.

Error in rsa_code (line 15)
e=randi(1,1,[2 n1]);

Islam Adam


How do I use this code to encrypt files?

fang zheng

thank you..

missing a function, is this in an additional toolbox or base matlab is ok.
I'm using 2015b.

Undefined function or variable


you should use extended eucleudianalgorithm to search for d.
this implementation is incorrect
dec(enc(msg)) != msg


Updating code to work for even small prime numbers

changed the title to RSA algorithm

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux