SlideShare a Scribd company logo
1 of 20
Implementing RSA Encryption
in Java
RSA algorithm
• Select two large prime numbers
p, q
• Compute
n = p  q
v = (p-1)  (q-1)
• Select small odd integer k
relatively prime to v
gcd(k, v) = 1
• Compute d such that
(d  k)%v = (k  d)%v = 1
• Public key is (k, n)
• Private key is (d, n)
• example
p = 11
q = 29
n = 319
v = 280
k = 3
d = 187
• public key
(3, 319)
• private key
(187, 319)
Encryption and decryption
• Alice and Bob would like to communicate in private
• Alice uses RSA algorithm to generate her public and
private keys
– Alice makes key (k, n) publicly available to Bob and
anyone else wanting to send her private messages
• Bob uses Alice’s public key (k, n) to encrypt message M:
– compute E(M) =(Mk)%n
– Bob sends encrypted message E(M) to Alice
• Alice receives E(M) and uses private key (d, n) to
decrypt it:
– compute D(M) = (E(M)d)%n
– decrypted message D(M) is original message M
Outline of implementation
• RSA algorithm for key generation
– select two prime numbers p, q
– compute n = p  q
v = (p-1)  (q-1)
– select small odd integer k such that
gcd(k, v) = 1
– compute d such that
(d  k)%v = 1
• RSA algorithm for encryption/decryption
– encryption: compute E(M) = (Mk)%n
– decryption: compute D(M) = (E(M)d)%n
RSA algorithm for key generation
• Input: none
• Computation:
– select two prime integers p, q
– compute integers n = p  q
v = (p-1)  (q-1)
– select small odd integer k such that gcd(k, v) = 1
– compute integer d such that (d  k)%v = 1
• Output: n, k, and d
RSA algorithm for encryption
• Input: integers k, n, M
– M is integer representation of plaintext message
• Computation:
– let C be integer representation of ciphertext
C = (Mk)%n
• Output: integer C
– ciphertext or encrypted message
RSA algorithm for decryption
• Input: integers d, n, C
– C is integer representation of ciphertext message
• Computation:
– let D be integer representation of decrypted ciphertext
D = (Cd)%n
• Output: integer D
– decrypted message
This seems hard …
• How to find big primes?
• How to find mod inverse?
• How to compute greatest common divisor?
• How to translate text input to numeric values?
• Most importantly: RSA manipulates big numbers
– Java integers are of limited size
– how can we handle this?
• Two key items make the implementation easier
– understanding the math
– Java’s BigInteger class
What is a BigInteger?
• Java class to represent and perform operations on
integers of arbitrary precision
• Provides analogues to Java’s primitive integer
operations, e.g.
– addition and subtraction
– multiplication and division
• Along with operations for
– modular arithmetic
– gcd calculation
– generation of primes
• http://java.sun.com/j2se/1.4.2/docs/api/
Using BigInteger
• If we understand what mathematical computations are
involved in the RSA algorithm, we can use Java’s
BigInteger methods to perform them
• To declare a BigInteger named B
BigInteger B;
• Predefined constants
BigInteger.ZERO
BigInteger.ONE
Randomly generated primes
BigInteger probablePrime(int b, Random rng)
• Returns random positive BigInteger of bit length b
that is “probably” prime
– probability that BigInteger is not prime < 2-100
• Random is Java’s class for random number generation
• The following statement
Random rng = new Random();
creates a new random number generator named rng
probablePrime
• Example: randomly generate two BigInteger primes
named p and q of bit length 32 :
/* create a random number generator */
Random rng = new Random();
/* declare p and q as type BigInteger */
BigInteger p, q;
/* assign values to p and q as required */
p = BigInteger.probablePrime(32, rng);
q = BigInteger.probablePrime(32, rng);
Integer operations
• Suppose have declared and assigned values for p and q
and now want to perform integer operations on them
– use methods add, subtract, multiply, divide
– result of BigInteger operations is a BigInteger
• Examples:
BigInteger w = p.add(q);
BigInteger x = p.subtract(q);
BigInteger y = p.multiply(q);
BigInteger z = p.divide(q);
Greatest common divisor
• The greatest common divisor of two numbers x and y is
the largest number that divides both x and y
– this is usually written as gcd(x,y)
• Example: gcd(20,30) = 10
– 20 is divided by 1,2,4,5,10,20
– 30 is divided by 1,2,3,5,6,10,15,30
• Example: gcd(13,15) = 1
– 13 is divided by 1,13
– 15 is divided by 1,3,5,15
• When the gcd of two numbers is one, these numbers are
said to be relatively prime
Euler’s Phi Function
• For a positive integer n, (n) is the number of positive
integers less than n and relatively prime to n
• Examples:
– (3) = 2 1,2
– (4) = 2 1,2,3 (but 2 is not relatively prime to 4)
– (5) = 4 1,2,3,4
• For any prime number p,
(p) = p-1
• For any integer n that is the product of two distinct
primes p and q,
(n) = (p)(q)
= (p-1)(q-1)
Relative primes
• Suppose we have an integer x and want to find an odd
integer z such that
– 1 < z < x, and
– z is relatively prime to x
• We know that x and z are relatively prime if their
greatest common divisor is one
– randomly generate prime values for z until gcd(x,z)=1
– if x is a product of distinct primes, there is a value of z
satisfying this equality
Relative BigInteger primes
• Suppose we have declared a BigInteger x and
assigned it a value
• Declare a BigInteger z
• Assign a prime value to z using the probablePrime
method
– specifying an input bit length smaller than that of x
gives a value z<x
• The expression
(x.gcd(z)).equals(BigInteger.ONE)
returns true if gcd(x,z)=1 and false otherwise
• While the above expression evaluates to false, assign a
new random to z
Multiplicative identities and inverses
• The multiplicative identity is the element e such that
e  x = x  e = x
for all elements xX
• The multiplicative inverse of x is the element x-1 such that
x  x-1 = x-1  x = 1
• The multiplicative inverse of x mod n is the element x-1
such that
(x  x-1) mod n = (x-1  x ) mod n = 1
– x and x-1 are inverses only in multiplication mod n
modInverse
• Suppose we have declared BigInteger variables x, y
and assigned values to them
• We want to find a BigInteger z such that
(x*z)%y =(z*x)%y = 1
that is, we want to find the inverse of x mod y and
assign its value to z
• This is accomplished by the following statement:
BigInteger z = x.modInverse(y);
Implementing RSA key generation
• We know have everything we need to implement the
RSA key generation algorithm in Java, so let’s get
started …

More Related Content

Similar to implementing the encryption in the JAVA.ppt

On the Secrecy of RSA Private Keys
On the Secrecy of RSA Private KeysOn the Secrecy of RSA Private Keys
On the Secrecy of RSA Private KeysDharmalingam Ganesan
 
Ibe weil pairing
Ibe weil pairingIbe weil pairing
Ibe weil pairingsravanbabu
 
Cryptography using rsa cryptosystem
Cryptography using rsa cryptosystemCryptography using rsa cryptosystem
Cryptography using rsa cryptosystemSamdish Arora
 
Crypto cs36 39
Crypto cs36 39Crypto cs36 39
Crypto cs36 39sravanbabu
 
Broadcasting and low exponent rsa attack
Broadcasting and low exponent rsa attackBroadcasting and low exponent rsa attack
Broadcasting and low exponent rsa attackAnkita Kapratwar
 
NumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.pptNumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.pptIshwariKhanal
 
Paillier Cryptosystem
Paillier CryptosystemPaillier Cryptosystem
Paillier CryptosystemDejan Radic
 
14-applications-of-number-theory.ppt
14-applications-of-number-theory.ppt14-applications-of-number-theory.ppt
14-applications-of-number-theory.pptIdcIdk1
 
digital signature algo.pptx
digital signature algo.pptxdigital signature algo.pptx
digital signature algo.pptxBLACKSPAROW
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmVaibhav Khanna
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxvaishnavi339314
 
Elliptic Curve Cryptography
Elliptic Curve CryptographyElliptic Curve Cryptography
Elliptic Curve CryptographyKelly Bresnahan
 
Convolution presentation
Convolution presentationConvolution presentation
Convolution presentationSoham Mondal
 
815.07 machine learning using python.pdf
815.07 machine learning using python.pdf815.07 machine learning using python.pdf
815.07 machine learning using python.pdfSairaAtta5
 
Simple Overview Caesar and RSA Encryption_by_Tarek_Gaber
Simple Overview Caesar and RSA Encryption_by_Tarek_GaberSimple Overview Caesar and RSA Encryption_by_Tarek_Gaber
Simple Overview Caesar and RSA Encryption_by_Tarek_GaberTarek Gaber
 
RSA Algorithm.ppt
RSA Algorithm.pptRSA Algorithm.ppt
RSA Algorithm.pptArchanaT30
 

Similar to implementing the encryption in the JAVA.ppt (20)

New ppt.ppt
New ppt.pptNew ppt.ppt
New ppt.ppt
 
On the Secrecy of RSA Private Keys
On the Secrecy of RSA Private KeysOn the Secrecy of RSA Private Keys
On the Secrecy of RSA Private Keys
 
Ibe weil pairing
Ibe weil pairingIbe weil pairing
Ibe weil pairing
 
Cryptography using rsa cryptosystem
Cryptography using rsa cryptosystemCryptography using rsa cryptosystem
Cryptography using rsa cryptosystem
 
Crypto cs36 39
Crypto cs36 39Crypto cs36 39
Crypto cs36 39
 
Broadcasting and low exponent rsa attack
Broadcasting and low exponent rsa attackBroadcasting and low exponent rsa attack
Broadcasting and low exponent rsa attack
 
NumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.pptNumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.ppt
 
RSA ALGORITHM
RSA ALGORITHMRSA ALGORITHM
RSA ALGORITHM
 
Paillier Cryptosystem
Paillier CryptosystemPaillier Cryptosystem
Paillier Cryptosystem
 
14-applications-of-number-theory.ppt
14-applications-of-number-theory.ppt14-applications-of-number-theory.ppt
14-applications-of-number-theory.ppt
 
digital signature algo.pptx
digital signature algo.pptxdigital signature algo.pptx
digital signature algo.pptx
 
Codes and Isogenies
Codes and IsogeniesCodes and Isogenies
Codes and Isogenies
 
Computing on Encrypted Data
Computing on Encrypted DataComputing on Encrypted Data
Computing on Encrypted Data
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithm
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptx
 
Elliptic Curve Cryptography
Elliptic Curve CryptographyElliptic Curve Cryptography
Elliptic Curve Cryptography
 
Convolution presentation
Convolution presentationConvolution presentation
Convolution presentation
 
815.07 machine learning using python.pdf
815.07 machine learning using python.pdf815.07 machine learning using python.pdf
815.07 machine learning using python.pdf
 
Simple Overview Caesar and RSA Encryption_by_Tarek_Gaber
Simple Overview Caesar and RSA Encryption_by_Tarek_GaberSimple Overview Caesar and RSA Encryption_by_Tarek_Gaber
Simple Overview Caesar and RSA Encryption_by_Tarek_Gaber
 
RSA Algorithm.ppt
RSA Algorithm.pptRSA Algorithm.ppt
RSA Algorithm.ppt
 

More from MuhammadAbdullah311866

NVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdf
NVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdfNVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdf
NVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdfMuhammadAbdullah311866
 
GCCS-privacy-PP-final presentation-3-1.pptx
GCCS-privacy-PP-final presentation-3-1.pptxGCCS-privacy-PP-final presentation-3-1.pptx
GCCS-privacy-PP-final presentation-3-1.pptxMuhammadAbdullah311866
 
presentationcloud-18123333331185718.pptx
presentationcloud-18123333331185718.pptxpresentationcloud-18123333331185718.pptx
presentationcloud-18123333331185718.pptxMuhammadAbdullah311866
 
cybersecurity assessS-Ment-and-I(1).pptx
cybersecurity assessS-Ment-and-I(1).pptxcybersecurity assessS-Ment-and-I(1).pptx
cybersecurity assessS-Ment-and-I(1).pptxMuhammadAbdullah311866
 
Security-Monitoring-and-Improvement.pptx
Security-Monitoring-and-Improvement.pptxSecurity-Monitoring-and-Improvement.pptx
Security-Monitoring-and-Improvement.pptxMuhammadAbdullah311866
 
Responsibilities of the CSIRT--abss.pptx
Responsibilities of the CSIRT--abss.pptxResponsibilities of the CSIRT--abss.pptx
Responsibilities of the CSIRT--abss.pptxMuhammadAbdullah311866
 
Fusion-Center-ITS-Security-and-Privacy-Operations (1).pptx
Fusion-Center-ITS-Security-and-Privacy-Operations (1).pptxFusion-Center-ITS-Security-and-Privacy-Operations (1).pptx
Fusion-Center-ITS-Security-and-Privacy-Operations (1).pptxMuhammadAbdullah311866
 
bash_1_2021-command line introduction.pdf
bash_1_2021-command line introduction.pdfbash_1_2021-command line introduction.pdf
bash_1_2021-command line introduction.pdfMuhammadAbdullah311866
 
framework_update_report-yer20170301.pptx
framework_update_report-yer20170301.pptxframework_update_report-yer20170301.pptx
framework_update_report-yer20170301.pptxMuhammadAbdullah311866
 
cybersecurity_framework_webinar_2017.pptx
cybersecurity_framework_webinar_2017.pptxcybersecurity_framework_webinar_2017.pptx
cybersecurity_framework_webinar_2017.pptxMuhammadAbdullah311866
 
package module in the python environement.pptx
package module in the python environement.pptxpackage module in the python environement.pptx
package module in the python environement.pptxMuhammadAbdullah311866
 
Supply-Chain-Management-and-Cloud-Security.pptx
Supply-Chain-Management-and-Cloud-Security.pptxSupply-Chain-Management-and-Cloud-Security.pptx
Supply-Chain-Management-and-Cloud-Security.pptxMuhammadAbdullah311866
 
1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...
1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...
1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...MuhammadAbdullah311866
 
overview of principles of computerss.ppt
overview of principles of computerss.pptoverview of principles of computerss.ppt
overview of principles of computerss.pptMuhammadAbdullah311866
 
information security importance and use.ppt
information security importance and use.pptinformation security importance and use.ppt
information security importance and use.pptMuhammadAbdullah311866
 
compatibility and complexity in the IS.ppt
compatibility and complexity in the IS.pptcompatibility and complexity in the IS.ppt
compatibility and complexity in the IS.pptMuhammadAbdullah311866
 
turning test, how it works and winners.ppt
turning test, how it works and winners.pptturning test, how it works and winners.ppt
turning test, how it works and winners.pptMuhammadAbdullah311866
 
games, infosec, privacy, adversaries .ppt
games, infosec, privacy, adversaries .pptgames, infosec, privacy, adversaries .ppt
games, infosec, privacy, adversaries .pptMuhammadAbdullah311866
 
Authentication Authorization-Lesson-2-Slides.ppt
Authentication Authorization-Lesson-2-Slides.pptAuthentication Authorization-Lesson-2-Slides.ppt
Authentication Authorization-Lesson-2-Slides.pptMuhammadAbdullah311866
 
PTE-A Coaching- information slidess.pptx
PTE-A Coaching- information slidess.pptxPTE-A Coaching- information slidess.pptx
PTE-A Coaching- information slidess.pptxMuhammadAbdullah311866
 

More from MuhammadAbdullah311866 (20)

NVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdf
NVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdfNVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdf
NVIDIA DGX User Group 1st Meet Up_30 Apr 2021.pdf
 
GCCS-privacy-PP-final presentation-3-1.pptx
GCCS-privacy-PP-final presentation-3-1.pptxGCCS-privacy-PP-final presentation-3-1.pptx
GCCS-privacy-PP-final presentation-3-1.pptx
 
presentationcloud-18123333331185718.pptx
presentationcloud-18123333331185718.pptxpresentationcloud-18123333331185718.pptx
presentationcloud-18123333331185718.pptx
 
cybersecurity assessS-Ment-and-I(1).pptx
cybersecurity assessS-Ment-and-I(1).pptxcybersecurity assessS-Ment-and-I(1).pptx
cybersecurity assessS-Ment-and-I(1).pptx
 
Security-Monitoring-and-Improvement.pptx
Security-Monitoring-and-Improvement.pptxSecurity-Monitoring-and-Improvement.pptx
Security-Monitoring-and-Improvement.pptx
 
Responsibilities of the CSIRT--abss.pptx
Responsibilities of the CSIRT--abss.pptxResponsibilities of the CSIRT--abss.pptx
Responsibilities of the CSIRT--abss.pptx
 
Fusion-Center-ITS-Security-and-Privacy-Operations (1).pptx
Fusion-Center-ITS-Security-and-Privacy-Operations (1).pptxFusion-Center-ITS-Security-and-Privacy-Operations (1).pptx
Fusion-Center-ITS-Security-and-Privacy-Operations (1).pptx
 
bash_1_2021-command line introduction.pdf
bash_1_2021-command line introduction.pdfbash_1_2021-command line introduction.pdf
bash_1_2021-command line introduction.pdf
 
framework_update_report-yer20170301.pptx
framework_update_report-yer20170301.pptxframework_update_report-yer20170301.pptx
framework_update_report-yer20170301.pptx
 
cybersecurity_framework_webinar_2017.pptx
cybersecurity_framework_webinar_2017.pptxcybersecurity_framework_webinar_2017.pptx
cybersecurity_framework_webinar_2017.pptx
 
package module in the python environement.pptx
package module in the python environement.pptxpackage module in the python environement.pptx
package module in the python environement.pptx
 
Supply-Chain-Management-and-Cloud-Security.pptx
Supply-Chain-Management-and-Cloud-Security.pptxSupply-Chain-Management-and-Cloud-Security.pptx
Supply-Chain-Management-and-Cloud-Security.pptx
 
1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...
1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...
1-William Stallings - Effective Cybersecurity_ A Guide to Using Best Practice...
 
overview of principles of computerss.ppt
overview of principles of computerss.pptoverview of principles of computerss.ppt
overview of principles of computerss.ppt
 
information security importance and use.ppt
information security importance and use.pptinformation security importance and use.ppt
information security importance and use.ppt
 
compatibility and complexity in the IS.ppt
compatibility and complexity in the IS.pptcompatibility and complexity in the IS.ppt
compatibility and complexity in the IS.ppt
 
turning test, how it works and winners.ppt
turning test, how it works and winners.pptturning test, how it works and winners.ppt
turning test, how it works and winners.ppt
 
games, infosec, privacy, adversaries .ppt
games, infosec, privacy, adversaries .pptgames, infosec, privacy, adversaries .ppt
games, infosec, privacy, adversaries .ppt
 
Authentication Authorization-Lesson-2-Slides.ppt
Authentication Authorization-Lesson-2-Slides.pptAuthentication Authorization-Lesson-2-Slides.ppt
Authentication Authorization-Lesson-2-Slides.ppt
 
PTE-A Coaching- information slidess.pptx
PTE-A Coaching- information slidess.pptxPTE-A Coaching- information slidess.pptx
PTE-A Coaching- information slidess.pptx
 

Recently uploaded

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 

Recently uploaded (20)

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 

implementing the encryption in the JAVA.ppt

  • 2. RSA algorithm • Select two large prime numbers p, q • Compute n = p  q v = (p-1)  (q-1) • Select small odd integer k relatively prime to v gcd(k, v) = 1 • Compute d such that (d  k)%v = (k  d)%v = 1 • Public key is (k, n) • Private key is (d, n) • example p = 11 q = 29 n = 319 v = 280 k = 3 d = 187 • public key (3, 319) • private key (187, 319)
  • 3. Encryption and decryption • Alice and Bob would like to communicate in private • Alice uses RSA algorithm to generate her public and private keys – Alice makes key (k, n) publicly available to Bob and anyone else wanting to send her private messages • Bob uses Alice’s public key (k, n) to encrypt message M: – compute E(M) =(Mk)%n – Bob sends encrypted message E(M) to Alice • Alice receives E(M) and uses private key (d, n) to decrypt it: – compute D(M) = (E(M)d)%n – decrypted message D(M) is original message M
  • 4. Outline of implementation • RSA algorithm for key generation – select two prime numbers p, q – compute n = p  q v = (p-1)  (q-1) – select small odd integer k such that gcd(k, v) = 1 – compute d such that (d  k)%v = 1 • RSA algorithm for encryption/decryption – encryption: compute E(M) = (Mk)%n – decryption: compute D(M) = (E(M)d)%n
  • 5. RSA algorithm for key generation • Input: none • Computation: – select two prime integers p, q – compute integers n = p  q v = (p-1)  (q-1) – select small odd integer k such that gcd(k, v) = 1 – compute integer d such that (d  k)%v = 1 • Output: n, k, and d
  • 6. RSA algorithm for encryption • Input: integers k, n, M – M is integer representation of plaintext message • Computation: – let C be integer representation of ciphertext C = (Mk)%n • Output: integer C – ciphertext or encrypted message
  • 7. RSA algorithm for decryption • Input: integers d, n, C – C is integer representation of ciphertext message • Computation: – let D be integer representation of decrypted ciphertext D = (Cd)%n • Output: integer D – decrypted message
  • 8. This seems hard … • How to find big primes? • How to find mod inverse? • How to compute greatest common divisor? • How to translate text input to numeric values? • Most importantly: RSA manipulates big numbers – Java integers are of limited size – how can we handle this? • Two key items make the implementation easier – understanding the math – Java’s BigInteger class
  • 9. What is a BigInteger? • Java class to represent and perform operations on integers of arbitrary precision • Provides analogues to Java’s primitive integer operations, e.g. – addition and subtraction – multiplication and division • Along with operations for – modular arithmetic – gcd calculation – generation of primes • http://java.sun.com/j2se/1.4.2/docs/api/
  • 10. Using BigInteger • If we understand what mathematical computations are involved in the RSA algorithm, we can use Java’s BigInteger methods to perform them • To declare a BigInteger named B BigInteger B; • Predefined constants BigInteger.ZERO BigInteger.ONE
  • 11. Randomly generated primes BigInteger probablePrime(int b, Random rng) • Returns random positive BigInteger of bit length b that is “probably” prime – probability that BigInteger is not prime < 2-100 • Random is Java’s class for random number generation • The following statement Random rng = new Random(); creates a new random number generator named rng
  • 12. probablePrime • Example: randomly generate two BigInteger primes named p and q of bit length 32 : /* create a random number generator */ Random rng = new Random(); /* declare p and q as type BigInteger */ BigInteger p, q; /* assign values to p and q as required */ p = BigInteger.probablePrime(32, rng); q = BigInteger.probablePrime(32, rng);
  • 13. Integer operations • Suppose have declared and assigned values for p and q and now want to perform integer operations on them – use methods add, subtract, multiply, divide – result of BigInteger operations is a BigInteger • Examples: BigInteger w = p.add(q); BigInteger x = p.subtract(q); BigInteger y = p.multiply(q); BigInteger z = p.divide(q);
  • 14. Greatest common divisor • The greatest common divisor of two numbers x and y is the largest number that divides both x and y – this is usually written as gcd(x,y) • Example: gcd(20,30) = 10 – 20 is divided by 1,2,4,5,10,20 – 30 is divided by 1,2,3,5,6,10,15,30 • Example: gcd(13,15) = 1 – 13 is divided by 1,13 – 15 is divided by 1,3,5,15 • When the gcd of two numbers is one, these numbers are said to be relatively prime
  • 15. Euler’s Phi Function • For a positive integer n, (n) is the number of positive integers less than n and relatively prime to n • Examples: – (3) = 2 1,2 – (4) = 2 1,2,3 (but 2 is not relatively prime to 4) – (5) = 4 1,2,3,4 • For any prime number p, (p) = p-1 • For any integer n that is the product of two distinct primes p and q, (n) = (p)(q) = (p-1)(q-1)
  • 16. Relative primes • Suppose we have an integer x and want to find an odd integer z such that – 1 < z < x, and – z is relatively prime to x • We know that x and z are relatively prime if their greatest common divisor is one – randomly generate prime values for z until gcd(x,z)=1 – if x is a product of distinct primes, there is a value of z satisfying this equality
  • 17. Relative BigInteger primes • Suppose we have declared a BigInteger x and assigned it a value • Declare a BigInteger z • Assign a prime value to z using the probablePrime method – specifying an input bit length smaller than that of x gives a value z<x • The expression (x.gcd(z)).equals(BigInteger.ONE) returns true if gcd(x,z)=1 and false otherwise • While the above expression evaluates to false, assign a new random to z
  • 18. Multiplicative identities and inverses • The multiplicative identity is the element e such that e  x = x  e = x for all elements xX • The multiplicative inverse of x is the element x-1 such that x  x-1 = x-1  x = 1 • The multiplicative inverse of x mod n is the element x-1 such that (x  x-1) mod n = (x-1  x ) mod n = 1 – x and x-1 are inverses only in multiplication mod n
  • 19. modInverse • Suppose we have declared BigInteger variables x, y and assigned values to them • We want to find a BigInteger z such that (x*z)%y =(z*x)%y = 1 that is, we want to find the inverse of x mod y and assign its value to z • This is accomplished by the following statement: BigInteger z = x.modInverse(y);
  • 20. Implementing RSA key generation • We know have everything we need to implement the RSA key generation algorithm in Java, so let’s get started …