0% found this document useful (0 votes)
78 views12 pages

Rivest-Shamir - Adleman - Rsa: - Made by Sahil Bhatiya

The document discusses the RSA encryption algorithm. RSA (Rivest-Shamir-Adleman) is a public key cryptosystem invented in 1977 that is widely used for secure data transmission over the internet. It uses a public key and a private key, where the public key is used for encryption and can be shared publicly, while the private key is used for decryption and must be kept secret. The security of RSA is based on the difficulty of factoring large integers into their prime factors. The document provides an example of how RSA encryption and decryption works step-by-step.

Uploaded by

Bhavik Sanghar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views12 pages

Rivest-Shamir - Adleman - Rsa: - Made by Sahil Bhatiya

The document discusses the RSA encryption algorithm. RSA (Rivest-Shamir-Adleman) is a public key cryptosystem invented in 1977 that is widely used for secure data transmission over the internet. It uses a public key and a private key, where the public key is used for encryption and can be shared publicly, while the private key is used for decryption and must be kept secret. The security of RSA is based on the difficulty of factoring large integers into their prime factors. The document provides an example of how RSA encryption and decryption works step-by-step.

Uploaded by

Bhavik Sanghar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Rivest-

Shamir-
Adleman
- RSA  

- made by Sahil Bhatiya


Why Do You Need Encryption
•When you send something online, be it a
message, a comment, or an image – they carry
some ‘information’. That is, if you send a message
to me, I will be able to interpret the information
you are trying to convey. Similarly, if you are
sending an image to me, I will be able to see and
interpret the contents of the image.

•The RSA algorithm is one of the most widely


used encryption tools in use today. If you've used
computers made by Samsung, Toshiba, and LG,
you've probably used a device with an embedded
RSA-enabled chip.
RSA (Rivest-Shamir-Adleman) is a public key
cryptosystem that is widely used for secure
data transmission over the internet. It is
named after its inventors Ron Rivest, Adi
Shamir, and Leonard Adleman, who first
published the algorithm in 1977.

Computer scientists , Mathematician


Rivest-Shamir-Adleman -
RSA  

• 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.
• The RSA algorithm involves two keys, a public
key and a private key. The public key is used for
encryption and is available to anyone, while
the private key is used for decryption and must
be kept secret by the owner. The security of the
RSA algorithm is based on the difficulty of
factoring large integers into their prime factors.
4 Important terms

• Factor - numbers you can * and get


original number 1 2 3 4 6 12
• Prime - numbers divisible only 1 and itself
2 3 5 7 11 …
• Semi prime - product of two prime
number 2 5 = 10
• Modulo - reminder division 5 % 2 = 1
How the RSA algorithm works:
1. Key Generation:
• Choose two large prime numbers p and q.
• Calculate n = p * q.
• Calculate the totient function of n, φ(n) = (p-1) * (q-1).
• Choose an integer e such that 1 < e < φ(n) and
• gcd(e, φ(n)) = 1.
• Calculate d, the modular multiplicative inverse of e modulo φ(n), such that (d * e) mod φ(n)
= 1.
• The public key is (n, e) and the private key is d.
2. Encryption:
• Convert the plaintext message to a numerical value M.
• Encrypt the message by computing C = M^e mod n.
• The ciphertext C can be sent securely over the internet.
3. Decryption:
• Decrypt the ciphertext by computing M = C^d mod n.
• Convert the numerical value M back to the plaintext message.
EXAMPL 1. Key Generation:
E • Choose two prime numbers, p = 11 and q = 13.
• Calculate n = p * q = 11 * 13 = 143.
• Calculate φ(n) = (p-1) * (q-1) = 10 * 12 = 120.
• Choose a public exponent e such that 1 < e < φ(n) and
gcd(e, φ(n)) = 1. Let's choose e = 7.
• Calculate the private exponent d such that (d * e) mod
φ(n) = 1. We can use the Extended Euclidean
Algorithm to calculate d = 103.
• The public key is (n, e) = (143, 7) and the private key is
d = 103.
EXAMPL 2. Encryption:

E • Let's say we want to encrypt the message "HE". We can convert it to a


numerical value by representing each letter as its ASCII code, so "H"
becomes 72, "E" becomes 69. The message "HE" becomes the numerical
value 72 69
• We can encrypt each numerical value separately using the public key (n,
e).
• The first character 72 becomes 72^7 mod 143 = 61.
• The second character 69 becomes 69^7 mod 143 = 16.
• The encrypted message is therefore the numerical value 61 16
3. Decryption:
• To decrypt the message, we can use the private key d.
• We can decrypt each numerical value separately using the private key d.
• The first numerical value 61 becomes 61^103 mod 143 = 72, which
corresponds to the letter "H".
• The second numerical value 16 becomes 16^103 mod 143 = 69, which
corresponds to the letter "E".
• The decrypted message is therefore "HE".
Output :
import java.util.*;
//Encrypt Hello world message
import java.math.*;
Cipher encryptionCipher = Cipher.getInstance("RSA");
public key = MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsnw8XrLUhvUIA2BNbI9JiCJuon8neTicsf4cKix3/
import javax.crypto.BadPaddingException;
encryptionCipher.init(Cipher.ENCRYPT_MODE,privateKey);
c4cLKjDzDnjSx5gXu+xoAlkj8Wr1DQLNWp27nPBXoPnFX0hbQHiDvwN5epfrEetYZXRTyNN6MSs+I4KHLZojjHyD19YgIASFmIBC8/
import javax.crypto.Cipher;
d6orHa1k0JzR/xJpR5SecGL3EeSJrf7TkFr8jSyjH2TT5BIkiYtiOi8UX/90SWfEAMvDnqRNldbCoxezZlu6Db5Jis2E+Pfkk/
String message = "This is IT department";
Cyy1TFTy2bENTBGTcwXaM7l3k/rEVw6fxjjevis3+abcMor0MWlUOhWvv8N3oJsO00noBcjjj58geWoMqBpjtQIORYcCtnP5eX0KwIDAQAB
import javax.crypto.IllegalBlockSizeException;
byte[] encryptedMessage =
private key = MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCyfDxestSG9QgDYE1sj0mIIm6ifyd5OJyx/
import javax.crypto.NoSuchPaddingException;
hwqLHf9zhwsqMPMOeNLHmBe77GgCWSPxavUNAs1anbuc8Feg+cVfSFtAeIO/ encryptionCipher.doFinal(message.getBytes());
import java.security.*;
A3l6l+sR61hldFPI03oxKz4jgoctmiOMfIPX1iAgBIWYgELz93qisdrWTQnNH/EmlHlJ5wYvcR5Imt/tOQWvyNLKMfZNPkEiSJi2I6LxRf/
String encryption =
3RJZ8QAy8OepE2V1sKjF7NmW7oNvkmKzYT49+ST8LLLVMVPLZsQ1MEZNzBdozuXeT+sRXDp/GON6+Kzf5ptwyivQxaVQ6Fa+/
import java.util.Base64;
Base64.getEncoder().encodeToString(encryptedMessage);
w3egmw7TSegFyOOPnyB5agyoGmO1Ag5FhwK2c/l5fQrAgMBAAECggEAAiqe4vlhugekYsIa/nvYxSXB2QgZFxAYWtK+Tca/
public class RSA{
aB3F2sbrpYF4YFOMkOpw6gPjLBmWpdtB3ZKewfM2wCpytiCQNM4Gi+8ETiujoKg4Ewyp/
System.out.println("encrypted message = "+encryption);
z9q9S3Z+aRjvAh8yWkSypv6K4kibxIeeCG8TFoF5KgvCWDKQj0rTFBIRUacaWn7zrerhFXpBM+/
public static void main(String[] args) throws
//Decrypt Hello world message
vIa+lgGChHdugrZcwb2eM6kHRTqisbQlUpZWs1SqD6j9BSVjDPu6fxJi1AONGYI7NAxFovSWy6Gmg+wrXcmuD52pKzgnVjfV7f/
NoSuchAlgorithmException,
dcnBkW4H0mCnoFvtdWfODivZTDiz9cJoxx6efi4US0HjRNiTyQdZcV+ZNEQKBgQC7BjGwlvT4y4CL4OtpeIlXmrbcVtzmFvq+pAx7NUdU+X+MI
Cipher decryptionCipher = Cipher.getInstance("RSA");
NoSuchPaddingException, InvalidKeyException,
3PQVukZqUA2w20WfCppMsCKWpYO8EymN1HT9T/+dsIO0TCuCDOvJiApGTVWyM+H/
IllegalBlockSizeException, BadPaddingException { decryptionCipher.init(Cipher.DECRYPT_MODE,publicKey);
4fm7U8XR4HcnkJVbReg0w2iQX4Mr+vvCtG+e0QjTq4z67+Gr+C9k5pV2Bh4GwKBgQD0T9hnyqJO8+fGvgu8rj27qg8J2oTtK4oCM/
fZtHsYnFIHv3C5pXGuxKJVo879QMdU3eI67MUa8dHx343hNl9io+OHrwz9HqnhEr7z/
byte[] decryptedMessage =
KeyPairGenerator keyPairGenerator =
a3zO9cI7ph8vhoetJvEJ3cZpwmXbArqU1Cgz6a+N+rE1Rp0l8zFoelTC/k44jY/
PWJVMQKBgQCtonGNnokvV1gwBZDqKfNw9v3gkXCi2iDPz+Samvtv4/
KeyPairGenerator.getInstance("RSA"); decryptionCipher.doFinal(encryptedMessage);
fL9ro2agoePemVLljgMET7yBfEG5gHpIe1JdT9sUtJh55hPUwxtwGtEft3zKSdvvAWNmJJPndYiJYDapbxUshGEswsoRtS0h18oBHdA/
String decryption = new String(decryptedMessage);
SecureRandom secureRandom = new SecureRandom();
pdwVWwdKYreKxxtVDrdCY7kwKBgQC3GriYYZhwEAFgRMNLMFP4OKZ4vhvuHTmcGRLjSY8QjOg2Alcb7FFdqOX5xYG28Tvz8TBC9X1silzNKL2P
keyPairGenerator.initialize(2048,secureRandom); System.out.println("decrypted message = "+decryption);
U07+ANLguGPFuZucoo4XE8OxjuHFQf1rUJcG+FneE64Bvd1Ebadoo/TD8Z2I5yO/TfA7/
iFs5cKXiVvKNFBv6TOvoQKBgQCzOnXXEwjPVqROVAtTZ2rOsEgR04vGfU8o9cKhXzzdR7vO1P6lQNdfW5FXudruWotsM0GSHXzPbQNSisE6YNi
}
KeyPair pair = keyPairGenerator.generateKeyPair();
gfpip27yo/Pv+Zij3jwywcYMtK4lqUQdh7BKJ0NyYWGFzUzCo1ZP7pdlZNBeROGwjQr8SzrJEy6QMwxtV2vgE+Q==
PublicKey publicKey = pair.getPublic(); }

Output :
encrypted message = rIXS13MTfDoRJvwaopvIfB8LD79PrkwaIkRUZfmujdopPV3cc5EJy6X/qvkxCN16hTy3Yxn/Nf/kcfqIoOOXk8yL/
String publicKeyString =
k3Vbe6Lx5osUy/5cCV18x56M4zV2h8DGqieXPE+XLhYjEjToC5IZJ8W8xtOS/
9ub9tQRIO9vWdXzbE0GhEGIjif4+MHXeYQjzH9V4sVMi02Rio13xPa8uUjUWktPaZi1SAeKWLb9AeTpa/
Base64.getEncoder().encodeToString(publicKey.getEncoded());
z+etW0mEv12cZSAzY1vKmHyBLi8eE/
System.out.println("public key = "+ publicKeyString);
fDPSBbZOtaATSWnxxX7B3Z43CVp2SEdTGVP59GX8+vC4bakVuUVP9z0a8GlNn5xlc6Q3zY3odMpMW2y+w==
PrivateKeydecrypted
privateKey = pair.getPrivate();
message = This is IT department
String privateKeyString =
Base64.getEncoder().encodeToString(privateKey.getEncoded());
System.out.println("private key = "+ privateKeyString);
How is RSA secure? • Notes :

RSA security relies on the computational difficulty of factoring large • Encryption : message ^ E % N = Cipher
Text
integers. As computing power increases and more efficient factoring
• Decryption : Cipher Text ^ D % N =
algorithms are discovered, the ability to factor larger and larger numbers Message
also increases.
The result of RSA encryption is a huge batch of mumbo jumbo that takes
• Or
attackers a lot of time and processing power to break.
Real life examples: online transactions, such as online shopping and banking.
• Encryption : message ^ D % N = Cipher
Digital signatures etc Text
• Decryption : Cipher Text ^ E % N =
Message

Thank You

You might also like