0% found this document useful (0 votes)
10 views15 pages

NSC_RSA

The document outlines the RSA algorithm, a significant public key cryptography method developed by Rivest, Shamir, and Adleman in 1977. It explains the process of key generation, encryption, and decryption, highlighting the use of public and private keys. Additionally, it discusses the applications of public-key cryptography, including encryption, digital signatures, and key exchange.

Uploaded by

vidhathrigujji
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)
10 views15 pages

NSC_RSA

The document outlines the RSA algorithm, a significant public key cryptography method developed by Rivest, Shamir, and Adleman in 1977. It explains the process of key generation, encryption, and decryption, highlighting the use of public and private keys. Additionally, it discusses the applications of public-key cryptography, including encryption, digital signatures, and key exchange.

Uploaded by

vidhathrigujji
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/ 15

Network Security & Cryptography

Lab
WEEK-8: Write a program to implement RSA algorithm

Public Key Cryptography


• probably most significant advance in the 3000 year
history of cryptography
• uses two keys – a public & a private key
• asymmetric since parties are not equal
• uses clever application of number theoretic concepts
to function
• complements rather than replaces private key crypto
Why Public-Key Cryptography?
• developed to address two key issues:
• key distribution – how to have secure communications in
general without having to trust a KDC with your key
• digital signatures – how to verify a message comes intact
from the claimed sender
• public invention due to Whitfield Diffie & Martin
Hellman at Stanford Uni in 1976
• known earlier in classified community
Public-Key Cryptography
Symmetric vs Public-Key
Public-Key Cryptosystems
Public-Key Applications
• can classify uses into 3 categories:
• encryption/decryption (provide secrecy)
• digital signatures (provide authentication)
• key exchange (of session keys)
• some algorithms are suitable for all uses, others are
specific to one
Public-Key Cryptography /
Asymmetric key Cryptography

Hello Hello
bob bob

$gycK#
Kb&
Alice Bob

Alice’s Public Key Bob’s Public Key


(PU) (PU)

Alice’s Private Key Bob’s Private Key


(PR) (PR)

Bob’s Public Key


Alice’s Public Key
(PU)
(PU)
RSA
• by Rivest, Shamir & Adleman of MIT in 1977
• best known & widely used public-key scheme
RSA Key Setup
• each user generates a public/private key pair by:
• selecting two large primes at random - p, q
• computing their system modulus n=p.q
• note ø(n)=(p-1)(q-1)
• selecting at random the encryption key e
• where 1<e<ø(n), gcd(e,ø(n))=1
• solve following equation to find decryption key d
• e.d=1 mod ø(n) and 0≤d≤n
• publish their public encryption key: PU={e,n}
• keep secret private decryption key: PR={d,n}
RSA Encryption and
Decryption
• to encrypt a message M the
sender:
• obtains public key of recipient RSA
PU={e,n}
• computes: C = Me mod n, where
0≤M<n
• to decrypt the ciphertext C the
owner:
• uses their private key PR={d,n}
• computes: M = Cd mod n
• note that the message M must be
smaller than the modulus n (block
if needed)
RSA Example - Key Setup

1. Select two prime numbers ‘p’ and ‘q’ p=17 & q=11
160)1281(8
2. Compute n = pq n = 17 x 11=187 1280
______
1
ø(n)=(17–1)(11-1)=16 x 10
3. Compute ø(n)=(p–1)(q-1) ø(n)=160

since
gcd(e,160)=1; choose e=7 183x7=1281=
4. Select e: where 1<e<ø(n), gcd(e,ø(n))=1
8x160+1
de=1 mod 160 and d < 160 Value is
5. Determine d: de=1 mod ø(n) and 0≤d≤n d=183

6. Publish public key PU= {e,n} PU={7,187}

7. Keep secret private key PR={d,n} PR={183,187}


RSA Example - En/Decryption

• sample RSA encryption/decryption is:


• given message M = 88 (nb. 88<187)
• encryption:
C = Me mod n, where 0≤M<n PU={7,187}
C = 887 mod 187 = 11
• decryption:
M = Cd mod n PR={183,187}
M = 11183 mod 187 = 88
#include <stdio.h>
int ex_gcd(int a,int b,int n) //computes the GCD using the Extended Euclid method
{
int x=0,y=1,lastx=1,lasty=0;
int temp,q;
while(b!=0)
{
temp =b;
q = a/b;
b = a%b;
a = temp;
temp=x;
x = lastx - q*x;
lastx = temp;
temp =y;
y = lasty - q*y;
lasty = temp;
}
if(n==1) return a;
else return lasty;
}
long en_de(int base, int exp,int n)
{
int b[30],i,c=0;
long d=1;
for(i=0;exp!=0;exp/=2,i++)

You might also like