14 Applications of Number Theory

download 14 Applications of Number Theory

of 42

Transcript of 14 Applications of Number Theory

  • 8/9/2019 14 Applications of Number Theory

    1/42

    1

    Applications of Number

    Theory

    CS 202

    Epp section 10.4Aaron Bloomfield

  • 8/9/2019 14 Applications of Number Theory

    2/42

    2

    About this lecture set

    ! "ant to introduce #SA$ The most commonly used crypto%raphic al%orithm

    today

    &uch of the underlyin% theory "e "ill not be ableto %et to$ !t's beyond the scope of this course

    &uch of "hy this all "or(s "on't be tau%ht$ !t's )ust an introduction to ho" it "or(s

  • 8/9/2019 14 Applications of Number Theory

    3/42

  • 8/9/2019 14 Applications of Number Theory

    4/42

    4

    *ublic (ey crypto%raphy

    E+erybody has a (ey that encrypts and a

    separate (ey that decrypts

    $ They are not interchan%able

    The encryption (ey is made public

    The decryption (ey is (ept pri+ate

  • 8/9/2019 14 Applications of Number Theory

    5/42

    5

    *ublic (ey crypto%raphy %oals

    ey %eneration should be relati+ely easy

    Encryption should be easy

    3ecryption should be easy

    $ ith the ri%ht (ey

    Crac(in% should be veryhard

  • 8/9/2019 14 Applications of Number Theory

    6/42

    6

    !s that number prime

    5se the 6ermat primality test

    7i+en8

    $ n8 the number to test for primality

    $ k8 the number of times to test -the certainty/

    The al%orithm is8repeat ktimes:

    pick arandomly in the range [1, n1]

    if an1mod n 1 then return composite

    return probably prime

  • 8/9/2019 14 Applications of Number Theory

    7/42

    7

    !s that number prime

    The al%orithm is8repeat ktimes:

    pick arandomly in the range [1, n1]

    if an1mod n 1 then return composite

    return probably prime

    9et n: 10;

    $ !teration 18 a:

  • 8/9/2019 14 Applications of Number Theory

    8/42

    8

    !s that number prime

    The al%orithm is8repeat ktimes:

    pick arandomly in the range [1, n1]

    if an1mod n 1 then return composite

    return probably prime

    9et n: 101

    $ !teration 18 a: ;;8 ;;100mod 101 : 1

    $ !teration 28 a: ?08 ?0100

    mod 101 : 1$ !teration @8 a: 148 14100mod 101 : 1

    $ !teration 48 a: @8 @100mod 101 : 1

    $At this point> 101 has a -/4 : 1,1? chance of still

    bein% composite

  • 8/9/2019 14 Applications of Number Theory

    9/42

    9

    &ore on the 6ermat primality test

    Each iteration hal+es the probability that the number is a

    composite

    $ *robability : -/k

    $ !f k: 100> probability it's a composite is -/100: 1 in 1.2 10@0

    that the number is composite 7reater chance of ha+in% a hard"are error

    $ Thus> k: 100 is a %ood +alue

    o"e+er> this is not certain$ There are (no"n numbers that are composite but "ill al"ays

    report prime by this test

    Source8 http8,,en."i(ipedia.or%,"i(i,6ermatprimalitytest

  • 8/9/2019 14 Applications of Number Theory

    10/42

    10

    Googles recruitment campaignGoogles recruitment campaign

  • 8/9/2019 14 Applications of Number Theory

    11/42

    11

    #SA

    Stands for the in+entors8 #on #i+est> Adi Shamir

    and 9en Adleman

    Three parts8$ ey %eneration

    $ Encryptin% a messa%e

    $ 3ecryptin% a messa%e

  • 8/9/2019 14 Applications of Number Theory

    12/42

    12

    ey %eneration steps

    1. Choose t"o random lar%e prime numbers p D q> and

    n:pq

    2. Choose an inte%er 1 F eF n"hich is relati+ely prime to-pG1/-qG1/

    @. Compute dsuch that d * eH 1 -mod -pG1/-qG1//

    $ #ephrased8 de mod -pG1/-qG1/ : 1

    4. 3estroy all records ofpand q

  • 8/9/2019 14 Applications of Number Theory

    13/42

    13

    ey %eneration> step 1

    Choose t"o randomlar%e prime numberspD q

    $ !n reality> 204= bit numbers are recommended

    That's ?1 di%its

    $ 6rom last lecture8 chance of a random odd 204= bitnumber bein% prime is about 1,10

    e can compute if a number is prime relati+ely Iuic(ly +ia

    the 6ermat primality test

    e choosep: 10 and q:

  • 8/9/2019 14 Applications of Number Theory

    14/42

    14

    ey %eneration> step 1

    Ja+a code to find a bi% prime number8

    BigInteger prime = ne BigInteger!numBits, certainty, random"#

    The number ofbits of the prime

    Certainty that the

    number is a prime

    The random number

    %enerator

  • 8/9/2019 14 Applications of Number Theory

    15/42

    15

    ey %eneration> step 1

    Ja+a code to find a bi% prime number8

    import $a%a&math&'#import $a%a&util&'#

    class Big(rime )

    static int num*igits = +1#static int certainty = 1--#

    static final double ./02 = 3ath&log!1-"43ath&log!2"#

    static int numBits = !int" !num*igits ' ./02"#

    public static %oid main !5tring args[]" )6andom random = ne 6andom!"#BigInteger prime = ne BigInteger !numBits, certainty,

    random"#5ystem&out&println !prime"#

    77

  • 8/9/2019 14 Applications of Number Theory

    16/42

    16

    ey %eneration> step 1

    o" lon% does this ta(e

    $ eep in mind this is Ja+a

    $ These tests done on a =;0 &hK *entium machine

    $A+era%e of 100 trials -certainty : 100/

    $ 200 di%its -??4 bits/8 about 1.; seconds

    $ ?1 di%its -204= bits/8 about ; seconds

  • 8/9/2019 14 Applications of Number Theory

    17/42

    18

    ey %eneration> step 1

    *ractical considerations

    $ pand qshould not be too close to%ether

    $ -pG1/ and -qG1/ should not ha+e small prime factors

    $ 5se a %ood random number %enerator

  • 8/9/2019 14 Applications of Number Theory

    18/42

    19

    ey %eneration> step 2

    Choose an inte%er 1 F eF n"hich is relati+ely

    prime to -pG1/-qG1/

    There are al%orithms to do this efficiently$ e aren't %oin% o+er them in this course

    Easy "ay to do this8 ma(e ebe a prime number$ !t only has to be relati+ely prime to -pG1/-qG1/> but can

    be fully prime

  • 8/9/2019 14 Applications of Number Theory

    19/42

  • 8/9/2019 14 Applications of Number Theory

    20/42

    21

    ey %eneration> step @

    Compute dsuch that8

    d * eH 1 -mod -pG1/-qG1//$ #ephrased8 de mod -pG1/-qG1/ : 1

    There are al%orithms to do this efficiently$ e aren't %oin% o+er them in this course

    e choose d: 4?? step @

    Ja+a code to find d8

    import $a%a&math&'#

    class 8ind* )

    public static %oid main !5tring args[]" )

    BigInteger p9 = ne BigInteger!1-1+"#BigInteger e = ne BigInteger !;

  • 8/9/2019 14 Applications of Number Theory

    22/42

    23

    ey %eneration> step 4

    3estroy all records ofpand q

    !f "e (no" p and q> then "e can compute the

    pri+ate encryption (ey from the public decryption(ey

    d * eH 1 -mod -pG1/-qG1//

  • 8/9/2019 14 Applications of Number Theory

    23/42

    24

    The (eys

    e ha+e n:pq: 10@ e: =;> and d: 4??e/ : -10@ =;/

    The pri+ate (ey is -n>d/ : -10@ 4?? nis not pri+ate

    $ Lnly dis pri+ate

    !n reality>d and eare ?00 -or so/ di%it numbers

    $ Thus nis a 1200 -or so/ di%it number

  • 8/9/2019 14 Applications of Number Theory

    24/42

    25

    Encryptin% messa%es

    To encode a messa%e81. Encode the messa%e minto a number

    2. Split the number into smaller numbers mF n

    @. 5se the formula c = me

    mod n cis the cipherteMt> and mis the messa%e

    Ja+a code to do the last step8

    $ m.mod*o" -e> n/$ here the ob)ect m is the Bi%!nte%er to encrypt

  • 8/9/2019 14 Applications of Number Theory

    25/42

    26

    Encryptin% messa%es eMample

    1. Encode the messa%e into a number$ Strin% is 7o Ca+aliersO$ &odified ASC!! codes8

    41 =1 02 @ ? == ? = ; 1 =4 =; 0@ 0@

    2. Split the number into numbers F n$ #ecall that n: 10@