SlideShare a Scribd company logo
1 of 5
RSA Algorithm
 Choose p = 3 and q = 11
 Compute n = p * q = 3 * 11 = 33
 Compute φ(n) = (p - 1) * (q - 1) = 2 * 10 = 20
 Choose e such that 1 < e < φ(n) and e and n are coprime. Let e = 7
 Compute a value for d such that (d * e) % φ(n) = 1. One solution is d = 3 [(3 *
7) % 20 = 1]
 Public key is (e, n) => (7, 33)
 Private key is (d, n) => (3, 33)
 The encryption of m = 2 is c = 27
% 33 = 29
 The decryption of c = 29 is m = 293
% 33 = 2
Diffie-Hellman key exchange
A. The idea
Suppose two people, Alice and Bob [traditional names], want to use insecure email to
agree on a secret "shared key" that they can use to do further encryption for a long
message. How is that possible? The so-called Diffie-Hellman method provides a way.
This method is one of the ingredients of SSL, the encryption package that is part of
the Netscape browser.
These notes are a little more detailed than in class, for clarity, but on the exam you are
responsible only for doing exercises like Problem 8.2.
B. The mod function
The main ingredient is the "remainder" or "modulo" or "mod" function, denoted % in
Perl. For example, 25%10 is 5 (say "25 mod 10 is 5") and 25%16 is 9 ("25 mod 16 is 9").
For n%10, the result will always be one of 0,1,...,9.
As you can see, any positive integer modulo 10 is just the last digit in base
10: 1537%10 is 7, etc. You can think of "modulo 10" for positive integers as meaning
"ignore all decimal digits except the last one".
Doing "modular arithmetic" with "modulus" 10 means doing addition, subtraction,
and multiplication (including powers) where you only care about the remainder
modulo 10. You can use some other modulus m instead of 10, as long as it's the same
through the whole problem. It works very smoothly.
The "as often as you want" principle: If you are doing modular arithmetic to find
an the answer modulo m, you can take the remainder modulo m as often as you want
during the calculations, without changing the answer.
Example 1. To find 1537 x 4248 modulo 10, you could multiply out and take the last
digit, but a better way would be to replace 1537 by 7 and 4248 by 8 to start, find 7 x 8
= 56, and then take 56 mod 10 to get 6 as the answer.
A handy standard notation is to write a b (mod m) if a and b have the same
remainder modulo m. This is read "a is congruent to b modulo m". In this notation the
example just mentioned looks like this: 1537 x 4248 7 x 8 = 56 6 (mod 10).
Example 2. Find 28
(mod 11).
One solution. 28
= 256; 11 goes into 256 with quotient 23 and remainder 3.
Another solution. Find 22
, 24
, 28
by squaring repeatedly, but take remainders mod 11
each chance you get: 22
= 4, 24
= 42
= 16 5, 28
52
= 25 3.
Example 3. Find all the powers of 2 up to 210
, each modulo 11.
Solution. Keep doubling, taking remainders modulo 11 whenever possible:
2, 4, 8, 16 5, 10, 20 9, 18 7, 14 3, 6, 12 1 (mod 11). So the answer is 2,
4, 8, 5, 10, 9, 7, 3, 6, 1.
Notice that the powers of 2 run through all possible remainders modulo 11, except 0.
We say 2 is a "generator" modulo 11. There is a theorem that if you take
aprime modulus, then there is always some generator, and in fact 2 often works. If 2
doesn't, maybe 3 will.
C. The Diffie-Hellman method
The idea of Diffie and Hellman is that it's easy to compute powers modulo a prime but
hard to reverse the process: If someone asks which power of 2 modulo 11 is 7, you'd
have to experiment a bit to answer, even though 11 is a small prime. If you use a huge
prime istead, then this becomes a very difficult problem even on a computer. Steps:
1. Alice and Bob, using insecure communication, agree on a huge prime p and a
generator g. They don't care if someone listens in.
2. Alice chooses some large random integer xA < p and keeps it secret. Likewise
Bob chooses xB < p and keeps it secret. These are their "private keys".
3. Alice computes her "public key" yA gx
A (mod p) and sends it to Bob using
insecure communication. Bob computes his public key yB gx
B and sends it to
Alice. Here 0 < yA < p, 0 < yB < p.
As already mentioned, sending these public keys with insecure communication
is safe because it would be too hard for someone to compute xA from yAor
xB from yB, just like the powers of 2 above.
4. Alice computes zA yB
x
A (mod p) and Bob computes zB yA
x
B (mod p). Here
zA < p, zB < p.
But zA = zB, since zA yB
x
A (gx
B )x
A = g(x
A
x
B
)
(mod p) and similarly zB
(gx
A )x
B = g(x
A
x
B
)
(mod p). So this value is their shared secret key. They can
use it to encrypt and decrypt the rest of their communication by some faster
method.
In this calculation, notice that the step yB
x
A (gx
B )x
A involved replacing
g x
B by its remainder yB, (in the reverse direction) so we were really using the
"as often as you want" principle.
D. Notes (not on final exam)
 It's easy to see why the "as often as you want" principle works for modular
arithmetic with positive integers in base 10. In Example 1, imagine doing the
multiplication with paper-and-pencil arithmetic, but ignoring everything except
the last digit. You get
 ...7
 x ...8
 -------
 ...6
 ....
 ....
 ....
 -------
......6
In other words, you can multiply and then take the last digit, or you can take
remainders early, by saving just the 7 and 8, taking their product, and saving its
last digit.
 Congruences work fine for negative numbers if you always use a remainder
that is positive or 0; for example, -13 7 (mod 10) because -20 is a multiple of
10 and -13 is 7 larger. The % operation in Perl works this way but the same
operation in C and C++ does not.
 The notation is meant to suggest =, because several properties of are
similar to those of =. For example, a b and b c give a c (all mod m).
 Another interesting fact is that modulo 11, we have 210
1, 310
1, 410
1,...,1010
1, and of course 110
=1 to start with. More generally, there is a
theorem saying that for any prime p and for any a from 1 to p-1 we get ap-1
1
(mod p).
 The Diffie-Hellman method works best if p = 2q+1 where q is also a prime.
(For example, 5 and 11 are prime and 11 = 2 x 5 + 1.) Then half the integers
1,2,...,p-1 are generators, and it is possible to check whether g is a generator
just by seeing whether gq
-1 (mod p).
 Diffie-Hellman does have a weakness: If an intruder Charlie can intercept and
resend email between Alice and Bob, then the intruder can pretend to be Bob
for Alice and pretend to be Alice for Bob, substituting his own yC and tricking
each of Alice and Bob into having a shared secret key with him. There are ways
to fix this problem.
 The Diffie-Hellman method illustrates the concept of "public-key
cryptography", where people can give out public information that enables other
people to send them encrypted information.
E. An example
For Diffie-Hellman to be secure, it is desirable to use a prime p with 1024 bits; in base
10 that would be about 308 digits. An example, expressed in hexadecimal, is
p= de9b707d 4c5a4633 c0290c95 ff30a605 aeb7ae86 4ff48370 f13cf01c 49adb9f2
3d19a439 f743ee77 03cf342d 87f43110 5c843c78 ca4df639 931f3458 fae8a94d
1687e99a 76ed99d0 ba87189f 42fd31ad 8262c54a 8cf5914a e6c28c54 0d714a5f
6087a172 fb74f481 4c6f968d 72386ef3 45a05180 c3b3c7dd d5ef6fe7 6b0531c3
z= 56c03667 f3b50335 ad532d0a dcaa2897 a02c0878 099d8e3a ab9d80b2 b5c83e2f
14c78cee 664bce7d 209e0fd8 b73f7f68 22fcdf6f fade5af2 ddbb38ff 3d2270ce
bbed172d 7c399f47 ee9f1067 f1b85ccb ec8f43b7 21b4f980 2f3ea51a 8acd1f6f
b526ecf4 a45ad62b 0ac17551 727b6a7c 7aadb936 2394b410 611a21a7 711dcde2
To compute with huge integers like these, you need a special "multiple precision"
software package, because the built-in arithmetic on computer chips handles only 32
or 64 bits.
F. Solution to the homework problem
Here p=11, g=2, xA = 9, xB = 4. So yA = 2x
A = 29
(mod 11).
You can find this most easily by finding 22
=4, 24
= 42
= 16 (mod 11), 28
= (24
)2
52
= 25 3 (mod 11), and finally 29
= 2 x 28
2 x 3 = 6. So yA = 6.
Similary, 2x
B = 24
= 16 5 (mod 11), so yB = 5.
The secret shared key zA is the remainder of yB
x
A = 59
(mod 11). So find 52
= 25 3
(mod 11), 54
= (52
)2
32
= 9 (mod 11), 58
= (54
)2
92
= 81 4 (mod 11), 59
= 5 x
58
5 x 4 = 20 9 (mod 11). As a check, zB is the remainder of yA
x
B = 64
(mod 11).
62
= 36 3 (mod 11) so 64
= (62
)2
32
= 9 (mod 11), which checks. So zA = zB = 9.
Difference between MD-5 and SHA -1
 SHA-1 has a larger state: 160 bits vs 128 bits.
 SHA-1 has more rounds: 80 vs 64.
 SHA-1 rounds have an extra bit rotation and the mixing of state words is slightly different
(mostly to account for the fifth word).
 Bitwise combination functions and round constants are different.
 Bit rotation counts in SHA-1 are the same for all rounds, while in MD5 each round has its own
rotation count.
 The message words are pre-processed in SHA-0 and SHA-1. In MD5, each round uses one of
the 16 message words "as is"; in SHA-0, the 16 message words are expanded into 80 derived
words with a sort of word-wise linear feedback shift register. SHA-1 furthermore adds a bit
rotation to these word derivation.

More Related Content

What's hot

Factorising Common Factors
Factorising Common FactorsFactorising Common Factors
Factorising Common FactorsPassy World
 
Divide and-conquer multiply two polynomials
Divide and-conquer multiply two polynomialsDivide and-conquer multiply two polynomials
Divide and-conquer multiply two polynomialsHasanain Alshadoodee
 
Lesson 28: Integration by Substitution (worksheet solutions)
Lesson 28: Integration by Substitution (worksheet solutions)Lesson 28: Integration by Substitution (worksheet solutions)
Lesson 28: Integration by Substitution (worksheet solutions)Matthew Leingang
 
EULER AND FERMAT THEOREM
EULER AND FERMAT THEOREMEULER AND FERMAT THEOREM
EULER AND FERMAT THEOREMankita pandey
 
College textbook business math and statistics - section b - business mathem...
College textbook   business math and statistics - section b - business mathem...College textbook   business math and statistics - section b - business mathem...
College textbook business math and statistics - section b - business mathem...Praveen Tyagi
 
Varian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookVarian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookJosé Antonio PAYANO YALE
 
Mat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curvesMat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curvesGlenSchlee
 
Maths formula by viveksingh698@gmail.com
Maths formula by viveksingh698@gmail.comMaths formula by viveksingh698@gmail.com
Maths formula by viveksingh698@gmail.comvivek698
 
Polynomials and factoring
Polynomials and factoringPolynomials and factoring
Polynomials and factoringShilpi Singh
 
Factoring Polynomials to find its zeros
Factoring Polynomials to find its zerosFactoring Polynomials to find its zeros
Factoring Polynomials to find its zerosDaisy933462
 
Factoring polynomials
Factoring polynomialsFactoring polynomials
Factoring polynomialsNCVPS
 
QFP k=2 paper write-up
QFP k=2 paper write-upQFP k=2 paper write-up
QFP k=2 paper write-upBrice Merwine
 
Factoring GCF and Grouping
Factoring GCF and GroupingFactoring GCF and Grouping
Factoring GCF and Groupingswartzje
 
Common factor factorization
Common factor factorizationCommon factor factorization
Common factor factorizationZaheer Ismail
 
Lecture 03 factoring polynomials good one
Lecture 03 factoring polynomials good oneLecture 03 factoring polynomials good one
Lecture 03 factoring polynomials good oneHazel Joy Chong
 

What's hot (20)

Factorising Common Factors
Factorising Common FactorsFactorising Common Factors
Factorising Common Factors
 
Divide and-conquer multiply two polynomials
Divide and-conquer multiply two polynomialsDivide and-conquer multiply two polynomials
Divide and-conquer multiply two polynomials
 
Lesson 28: Integration by Substitution (worksheet solutions)
Lesson 28: Integration by Substitution (worksheet solutions)Lesson 28: Integration by Substitution (worksheet solutions)
Lesson 28: Integration by Substitution (worksheet solutions)
 
EULER AND FERMAT THEOREM
EULER AND FERMAT THEOREMEULER AND FERMAT THEOREM
EULER AND FERMAT THEOREM
 
College textbook business math and statistics - section b - business mathem...
College textbook   business math and statistics - section b - business mathem...College textbook   business math and statistics - section b - business mathem...
College textbook business math and statistics - section b - business mathem...
 
Varian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookVarian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution book
 
Mat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curvesMat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curves
 
Soluciones quiz
Soluciones quizSoluciones quiz
Soluciones quiz
 
Maths formula by viveksingh698@gmail.com
Maths formula by viveksingh698@gmail.comMaths formula by viveksingh698@gmail.com
Maths formula by viveksingh698@gmail.com
 
Ijetr012013
Ijetr012013Ijetr012013
Ijetr012013
 
Polynomials and factoring
Polynomials and factoringPolynomials and factoring
Polynomials and factoring
 
Factoring Polynomials to find its zeros
Factoring Polynomials to find its zerosFactoring Polynomials to find its zeros
Factoring Polynomials to find its zeros
 
Factoring polynomials
Factoring polynomialsFactoring polynomials
Factoring polynomials
 
QFP k=2 paper write-up
QFP k=2 paper write-upQFP k=2 paper write-up
QFP k=2 paper write-up
 
Rsa documentation
Rsa documentationRsa documentation
Rsa documentation
 
Factoring GCF and Grouping
Factoring GCF and GroupingFactoring GCF and Grouping
Factoring GCF and Grouping
 
Parabola
ParabolaParabola
Parabola
 
Common factor factorization
Common factor factorizationCommon factor factorization
Common factor factorization
 
Vertex
VertexVertex
Vertex
 
Lecture 03 factoring polynomials good one
Lecture 03 factoring polynomials good oneLecture 03 factoring polynomials good one
Lecture 03 factoring polynomials good one
 

Viewers also liked (17)

uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
Unit 2
Unit 2 Unit 2
Unit 2
 
Kai hwang solution
Kai hwang solutionKai hwang solution
Kai hwang solution
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
Unit1 2
Unit1 2 Unit1 2
Unit1 2
 
Vbscript
VbscriptVbscript
Vbscript
 
Html2
Html2Html2
Html2
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
Flow control
Flow controlFlow control
Flow control
 
As pnet
As pnetAs pnet
As pnet
 
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
Dtd
DtdDtd
Dtd
 
Icmp
IcmpIcmp
Icmp
 
Rip ospf and bgp
Rip ospf and bgpRip ospf and bgp
Rip ospf and bgp
 

Similar to Rsa example

CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx
CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptxCSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx
CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptxgbikorno
 
Asymmetric Cryptography.pptx
Asymmetric Cryptography.pptxAsymmetric Cryptography.pptx
Asymmetric Cryptography.pptxdiaa46
 
A study on number theory and its applications
A study on number theory and its applicationsA study on number theory and its applications
A study on number theory and its applicationsItishree Dash
 
Algebra factoring
Algebra factoringAlgebra factoring
Algebra factoringTrabahoLang
 
Assignment 2 (1) (1).docx
Assignment 2 (1) (1).docxAssignment 2 (1) (1).docx
Assignment 2 (1) (1).docxpinstechwork
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxvaishnavi339314
 
Calculus 08 techniques_of_integration
Calculus 08 techniques_of_integrationCalculus 08 techniques_of_integration
Calculus 08 techniques_of_integrationtutulk
 
Cyber Security Part-3.pptx
Cyber Security Part-3.pptxCyber Security Part-3.pptx
Cyber Security Part-3.pptxRavikumarVadana
 
Real numbers
Real numbersReal numbers
Real numbersRamki M
 
Demystifying Zero Knowledge Proofs [FINAL].pptx
Demystifying Zero Knowledge Proofs [FINAL].pptxDemystifying Zero Knowledge Proofs [FINAL].pptx
Demystifying Zero Knowledge Proofs [FINAL].pptxRedWhite12
 
CHAP6 Limits and Continuity.pdf
CHAP6 Limits and Continuity.pdfCHAP6 Limits and Continuity.pdf
CHAP6 Limits and Continuity.pdfmekkimekki5
 
ch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.pptch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.ppttahirnaquash2
 
Matlab_basic2013_1.pdf
Matlab_basic2013_1.pdfMatlab_basic2013_1.pdf
Matlab_basic2013_1.pdfabdul basit
 
Maths Revision Notes - IGCSE
Maths Revision Notes - IGCSEMaths Revision Notes - IGCSE
Maths Revision Notes - IGCSERahul Jose
 

Similar to Rsa example (20)

Prime
PrimePrime
Prime
 
Rsa cryptosystem
Rsa cryptosystemRsa cryptosystem
Rsa cryptosystem
 
Other public key systems
Other public key systemsOther public key systems
Other public key systems
 
CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx
CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptxCSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx
CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx
 
OTP basic
OTP basicOTP basic
OTP basic
 
Asymmetric Cryptography.pptx
Asymmetric Cryptography.pptxAsymmetric Cryptography.pptx
Asymmetric Cryptography.pptx
 
A study on number theory and its applications
A study on number theory and its applicationsA study on number theory and its applications
A study on number theory and its applications
 
Algebra factoring
Algebra factoringAlgebra factoring
Algebra factoring
 
Assignment 2 (1) (1).docx
Assignment 2 (1) (1).docxAssignment 2 (1) (1).docx
Assignment 2 (1) (1).docx
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptx
 
Calculus 08 techniques_of_integration
Calculus 08 techniques_of_integrationCalculus 08 techniques_of_integration
Calculus 08 techniques_of_integration
 
Cyber Security Part-3.pptx
Cyber Security Part-3.pptxCyber Security Part-3.pptx
Cyber Security Part-3.pptx
 
Real numbers
Real numbersReal numbers
Real numbers
 
Demystifying Zero Knowledge Proofs [FINAL].pptx
Demystifying Zero Knowledge Proofs [FINAL].pptxDemystifying Zero Knowledge Proofs [FINAL].pptx
Demystifying Zero Knowledge Proofs [FINAL].pptx
 
CHAP6 Limits and Continuity.pdf
CHAP6 Limits and Continuity.pdfCHAP6 Limits and Continuity.pdf
CHAP6 Limits and Continuity.pdf
 
ch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.pptch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.ppt
 
Ch04
Ch04Ch04
Ch04
 
Matlab_basic2013_1.pdf
Matlab_basic2013_1.pdfMatlab_basic2013_1.pdf
Matlab_basic2013_1.pdf
 
Maths tricks -1
Maths tricks -1Maths tricks -1
Maths tricks -1
 
Maths Revision Notes - IGCSE
Maths Revision Notes - IGCSEMaths Revision Notes - IGCSE
Maths Revision Notes - IGCSE
 

More from Abhishek Kesharwani (20)

uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Unit 1 web technology uptu slide
Unit 1 web technology uptu slideUnit 1 web technology uptu slide
Unit 1 web technology uptu slide
 
Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1 Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1
 
Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1 Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1
 
Mtech syllabus computer science uptu
Mtech syllabus computer science uptu Mtech syllabus computer science uptu
Mtech syllabus computer science uptu
 
Wi max tutorial
Wi max tutorialWi max tutorial
Wi max tutorial
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Tcp traffic control and red ecn
Tcp traffic control and red ecnTcp traffic control and red ecn
Tcp traffic control and red ecn
 
Schedulling
SchedullingSchedulling
Schedulling
 
Scheduling
SchedulingScheduling
Scheduling
 
Routers and planes (1)
Routers and planes (1)Routers and planes (1)
Routers and planes (1)
 
Routers and planes
Routers and planesRouters and planes
Routers and planes
 
Qo s rsvp......
Qo s rsvp......Qo s rsvp......
Qo s rsvp......
 

Rsa example

  • 1. RSA Algorithm  Choose p = 3 and q = 11  Compute n = p * q = 3 * 11 = 33  Compute φ(n) = (p - 1) * (q - 1) = 2 * 10 = 20  Choose e such that 1 < e < φ(n) and e and n are coprime. Let e = 7  Compute a value for d such that (d * e) % φ(n) = 1. One solution is d = 3 [(3 * 7) % 20 = 1]  Public key is (e, n) => (7, 33)  Private key is (d, n) => (3, 33)  The encryption of m = 2 is c = 27 % 33 = 29  The decryption of c = 29 is m = 293 % 33 = 2 Diffie-Hellman key exchange A. The idea Suppose two people, Alice and Bob [traditional names], want to use insecure email to agree on a secret "shared key" that they can use to do further encryption for a long message. How is that possible? The so-called Diffie-Hellman method provides a way. This method is one of the ingredients of SSL, the encryption package that is part of the Netscape browser. These notes are a little more detailed than in class, for clarity, but on the exam you are responsible only for doing exercises like Problem 8.2. B. The mod function The main ingredient is the "remainder" or "modulo" or "mod" function, denoted % in Perl. For example, 25%10 is 5 (say "25 mod 10 is 5") and 25%16 is 9 ("25 mod 16 is 9"). For n%10, the result will always be one of 0,1,...,9. As you can see, any positive integer modulo 10 is just the last digit in base 10: 1537%10 is 7, etc. You can think of "modulo 10" for positive integers as meaning "ignore all decimal digits except the last one". Doing "modular arithmetic" with "modulus" 10 means doing addition, subtraction, and multiplication (including powers) where you only care about the remainder modulo 10. You can use some other modulus m instead of 10, as long as it's the same through the whole problem. It works very smoothly.
  • 2. The "as often as you want" principle: If you are doing modular arithmetic to find an the answer modulo m, you can take the remainder modulo m as often as you want during the calculations, without changing the answer. Example 1. To find 1537 x 4248 modulo 10, you could multiply out and take the last digit, but a better way would be to replace 1537 by 7 and 4248 by 8 to start, find 7 x 8 = 56, and then take 56 mod 10 to get 6 as the answer. A handy standard notation is to write a b (mod m) if a and b have the same remainder modulo m. This is read "a is congruent to b modulo m". In this notation the example just mentioned looks like this: 1537 x 4248 7 x 8 = 56 6 (mod 10). Example 2. Find 28 (mod 11). One solution. 28 = 256; 11 goes into 256 with quotient 23 and remainder 3. Another solution. Find 22 , 24 , 28 by squaring repeatedly, but take remainders mod 11 each chance you get: 22 = 4, 24 = 42 = 16 5, 28 52 = 25 3. Example 3. Find all the powers of 2 up to 210 , each modulo 11. Solution. Keep doubling, taking remainders modulo 11 whenever possible: 2, 4, 8, 16 5, 10, 20 9, 18 7, 14 3, 6, 12 1 (mod 11). So the answer is 2, 4, 8, 5, 10, 9, 7, 3, 6, 1. Notice that the powers of 2 run through all possible remainders modulo 11, except 0. We say 2 is a "generator" modulo 11. There is a theorem that if you take aprime modulus, then there is always some generator, and in fact 2 often works. If 2 doesn't, maybe 3 will. C. The Diffie-Hellman method The idea of Diffie and Hellman is that it's easy to compute powers modulo a prime but hard to reverse the process: If someone asks which power of 2 modulo 11 is 7, you'd have to experiment a bit to answer, even though 11 is a small prime. If you use a huge prime istead, then this becomes a very difficult problem even on a computer. Steps: 1. Alice and Bob, using insecure communication, agree on a huge prime p and a generator g. They don't care if someone listens in. 2. Alice chooses some large random integer xA < p and keeps it secret. Likewise Bob chooses xB < p and keeps it secret. These are their "private keys".
  • 3. 3. Alice computes her "public key" yA gx A (mod p) and sends it to Bob using insecure communication. Bob computes his public key yB gx B and sends it to Alice. Here 0 < yA < p, 0 < yB < p. As already mentioned, sending these public keys with insecure communication is safe because it would be too hard for someone to compute xA from yAor xB from yB, just like the powers of 2 above. 4. Alice computes zA yB x A (mod p) and Bob computes zB yA x B (mod p). Here zA < p, zB < p. But zA = zB, since zA yB x A (gx B )x A = g(x A x B ) (mod p) and similarly zB (gx A )x B = g(x A x B ) (mod p). So this value is their shared secret key. They can use it to encrypt and decrypt the rest of their communication by some faster method. In this calculation, notice that the step yB x A (gx B )x A involved replacing g x B by its remainder yB, (in the reverse direction) so we were really using the "as often as you want" principle. D. Notes (not on final exam)  It's easy to see why the "as often as you want" principle works for modular arithmetic with positive integers in base 10. In Example 1, imagine doing the multiplication with paper-and-pencil arithmetic, but ignoring everything except the last digit. You get  ...7  x ...8  -------  ...6  ....  ....  ....  ------- ......6 In other words, you can multiply and then take the last digit, or you can take remainders early, by saving just the 7 and 8, taking their product, and saving its last digit.  Congruences work fine for negative numbers if you always use a remainder that is positive or 0; for example, -13 7 (mod 10) because -20 is a multiple of 10 and -13 is 7 larger. The % operation in Perl works this way but the same operation in C and C++ does not.
  • 4.  The notation is meant to suggest =, because several properties of are similar to those of =. For example, a b and b c give a c (all mod m).  Another interesting fact is that modulo 11, we have 210 1, 310 1, 410 1,...,1010 1, and of course 110 =1 to start with. More generally, there is a theorem saying that for any prime p and for any a from 1 to p-1 we get ap-1 1 (mod p).  The Diffie-Hellman method works best if p = 2q+1 where q is also a prime. (For example, 5 and 11 are prime and 11 = 2 x 5 + 1.) Then half the integers 1,2,...,p-1 are generators, and it is possible to check whether g is a generator just by seeing whether gq -1 (mod p).  Diffie-Hellman does have a weakness: If an intruder Charlie can intercept and resend email between Alice and Bob, then the intruder can pretend to be Bob for Alice and pretend to be Alice for Bob, substituting his own yC and tricking each of Alice and Bob into having a shared secret key with him. There are ways to fix this problem.  The Diffie-Hellman method illustrates the concept of "public-key cryptography", where people can give out public information that enables other people to send them encrypted information. E. An example For Diffie-Hellman to be secure, it is desirable to use a prime p with 1024 bits; in base 10 that would be about 308 digits. An example, expressed in hexadecimal, is p= de9b707d 4c5a4633 c0290c95 ff30a605 aeb7ae86 4ff48370 f13cf01c 49adb9f2 3d19a439 f743ee77 03cf342d 87f43110 5c843c78 ca4df639 931f3458 fae8a94d 1687e99a 76ed99d0 ba87189f 42fd31ad 8262c54a 8cf5914a e6c28c54 0d714a5f 6087a172 fb74f481 4c6f968d 72386ef3 45a05180 c3b3c7dd d5ef6fe7 6b0531c3 z= 56c03667 f3b50335 ad532d0a dcaa2897 a02c0878 099d8e3a ab9d80b2 b5c83e2f 14c78cee 664bce7d 209e0fd8 b73f7f68 22fcdf6f fade5af2 ddbb38ff 3d2270ce bbed172d 7c399f47 ee9f1067 f1b85ccb ec8f43b7 21b4f980 2f3ea51a 8acd1f6f b526ecf4 a45ad62b 0ac17551 727b6a7c 7aadb936 2394b410 611a21a7 711dcde2 To compute with huge integers like these, you need a special "multiple precision" software package, because the built-in arithmetic on computer chips handles only 32 or 64 bits. F. Solution to the homework problem Here p=11, g=2, xA = 9, xB = 4. So yA = 2x A = 29 (mod 11).
  • 5. You can find this most easily by finding 22 =4, 24 = 42 = 16 (mod 11), 28 = (24 )2 52 = 25 3 (mod 11), and finally 29 = 2 x 28 2 x 3 = 6. So yA = 6. Similary, 2x B = 24 = 16 5 (mod 11), so yB = 5. The secret shared key zA is the remainder of yB x A = 59 (mod 11). So find 52 = 25 3 (mod 11), 54 = (52 )2 32 = 9 (mod 11), 58 = (54 )2 92 = 81 4 (mod 11), 59 = 5 x 58 5 x 4 = 20 9 (mod 11). As a check, zB is the remainder of yA x B = 64 (mod 11). 62 = 36 3 (mod 11) so 64 = (62 )2 32 = 9 (mod 11), which checks. So zA = zB = 9. Difference between MD-5 and SHA -1  SHA-1 has a larger state: 160 bits vs 128 bits.  SHA-1 has more rounds: 80 vs 64.  SHA-1 rounds have an extra bit rotation and the mixing of state words is slightly different (mostly to account for the fifth word).  Bitwise combination functions and round constants are different.  Bit rotation counts in SHA-1 are the same for all rounds, while in MD5 each round has its own rotation count.  The message words are pre-processed in SHA-0 and SHA-1. In MD5, each round uses one of the 16 message words "as is"; in SHA-0, the 16 message words are expanded into 80 derived words with a sort of word-wise linear feedback shift register. SHA-1 furthermore adds a bit rotation to these word derivation.