This report to document the RSA code and how it works from encrypting certain message to how to decrypt it using general and private keys which will be generated in the given code.
1. RSA CODE REPORT
ABSTRACT
This report to document the RSA code
and how it works from encrypting
certain message to how to decrypt it
using general and private keys which
will be generated in the given code.
mohamed el saidy – 201400711
Under supervision:
Dr: Asharaf said
Eng: Mohamed Zidan
Discrete Math project
2. RSA(Rivest-Shamir-Adleman) Code Report
Abstract
This report to document the RSA code and how it works from encrypting certain message to how to
decrypt it using general and private keys which will be generated in the given code.
The sequence of the report will be as following (theory, RSA Algorithm, Matlap implementation, GUI
implementation, Challenges then recommendations).
Theory
Firstly, RSA is a cryptosystem for public-key encryption, and is widely used for securing sensitive data,
particularly when being sent over an insecure network such as the Internet.
RSA was first described in 1977 by Ron Rivest, Adi Shamir and Leonard Adleman of the Massachusetts
Institute of Technology. Public-key cryptography, also known as asymmetric cryptography, uses two
different but mathematically linked keys, one public and one private. The public key can be shared with
everyone, whereas the private key must be kept secret. In RSA cryptography, both the public and the
private keys can encrypt a message; the opposite key from the one used to encrypt a message is used to
decrypt it. This attribute is one reason why RSA has become the most widely used
asymmetric algorithm: It provides a method of assuring the confidentiality, integrity, authenticity and
non-reputability of electronic communications and data storage.
RSA derives its security from the difficulty of factoring large integers that are the product of two
large prime numbers. Multiplying these two numbers is easy, but determining the original prime
numbers from the total - factoring - is considered infeasible due to the time it would take even using
today’s super computers.
RSA Algorithm
The public and the private key-generation algorithm is the most complex part of RSA cryptography.
Two large prime numbers, p and q, are generated. A modulus n is calculated by multiplying p and q.
This number is used by both the public and private keys and provides the link between them. The public
key consists of the modulus n, and a public exponent, e as it's a prime number that is not too large.
The e figure doesn’t have to be a secretly selected prime number as the public key is shared with
everyone. The private key consists of the modulus n and the private exponent d, which is calculated
using the Extended Euclidean algorithm to find the multiplicative inverse with respect to the totient of n.
3. Matlap implementation
primegen.m
The first function which will be used to generate
the two large prime numbers.
Egen.m
This function to generate the e exponent
number in which (gcdf), implemented, is used
to assert that e is coprime with
m=(p-1)*(q-1).
Figure (1) prime generator function
Figure (2) e exponent generator function
4. This is the implementation code for the
gcdf.m function.
dgenf.m
This is the function which is used to generate d
which is used with n to decrypt the massage.
Figure (3) GCD function
Figure (4) d exponent generator function
5. encrypt.m
This function is used to convert certain
massage to the ciphered text(encrypted),
using e and n=p*q through this equation:
Me
mod n = C
(M: stand for massage and C: for ciphered
text)
decrypt.m
This function is used to the Ciphered text to
the original massage, using d and n=p*q
through this equation:
Cd
mod n = M
(M: stand for massage and C: for ciphered
text)
Figure (5) encryption function
Figure (6) decryption function
6. GUI implementation
The whole implemented functions have been used to create this simple GUI in Figure (7).
Figure (7) RSA GUI
7. Challenges
• Matlab has limited number of digits to store which in case of large numbers (ex..11 digits)
truncate the number which causes error in the process.
Recommendation
• Using language other than Matlab(ex.. C++) to create the project.
References
http://searchsecurity.techtarget.com/definition/RSA