Scribe:NimritaKoul
EntryNumber:2007mcs3136
Professor:Prof.Kavitha.Professor:Prof.Kavitha.
LectureDate:18/2/08
1
Aprimalitytestisatesttodetermine
whetherornotagivennumberisprime
2
whetherornotagivennumberisprime
withoutactuallydecomposingthe
numberintoitsconstituentprimefactors.
Theproblemofprimalitytesting
Fermat'sprimalitytest
MonteCarloalgorithmforprimalitytesting
AnalysisofAlgorithm..Claims1,2,3AnalysisofAlgorithm..Claims1,2,3
ModifiedAlgorithm
3
Givenanoddintegern+>=3,
Todetermineif“n”isprimeorcomposite
Goal:Designanalgorithmforthisproblem
whoserunningtimeispolynomialintheinputwhoserunningtimeispolynomialintheinput
length,ifnisvalueofinputitslengthisceiling
logn.
4
Fermat'slittletheoremstatesthatifpisprimeand1<=a<p,
thenap-1=1(modp).
Ifwewanttotestifpisprime,thenwecanpickrandoma's
intheintervalandseeiftheequalityholds.Iftheequality
doesnotholdforavalueofa,thenpiscomposite.Ifthe
equalitydoesholdformanyvaluesofa,thenwecansay
thatpisprobablyprime,orapseudoprime.thatpisprobablyprime,orapseudoprime.
Itmaybeinourteststhatwedonotpickanyvaluefora
suchthattheequalityfails.Anyasuchthatan-1=1(modn)
whenniscompositeisknownasaFermatliar.Ifwedopick
anasuchthatan-1≠1(modn)
thenaisknownasaFermatwitnessforthecompositenessof
n.
5
1.Choosearandomnumber“a”uniformlyat
randomfromtheset{1,2,3,….,n-1}.
Torepresentsuchanumberinbinary,logn
bitswillberequired,togettheselognbitswe
tossacoinlogntimes,itmaygiveanumber
bitswillberequired,togettheselognbitswe
tossacoinlogntimes,itmaygiveanumber
greaterthannandinthatcasewediscardit
andtossagain.
Thissteprequireslogntime.
6
2.Ifgdc(a,n)≠1thenreturncomposite
Elseaisrelativelyprimeton.
Supposen=p2thenfrom1,2,---,p2-1thereareSupposen=p2thenfrom1,2,---,p2-1thereare
psuchnumberswhichhavesamegcdasn,
thereforetheprobabilitytopicksuchano.is
p/p2=1/p.
7
Claim1:Ifnisprimethenforalla,suchthata
doesnotdividen,gcd(a,n)=1then
an-1=1(modn)
Foranyx,yandn,
Ifx=y(modn),thentheremainderwhenxisdividedby
nissameasremainderwhenyisdividedbynor(x-y)
isamultipleofn
i.e.x=k1n+r
y=k2n+r
8
Ifwepartitionthesetofnumberswithrespect
totheremaindersweobtaindifferentclassesof
integerswhereeachclassincludesnumbers
withsameremainderwhendividedbyn.
E.g.Z0={0,n,2n,,-n,-2n}
Z={1,n+1,2n+1,-n+1,-2n+1…}Z1={1,n+1,2n+1,-n+1,-2n+1…}
.
.
Zn={0,1,2,……,n-1}
9
SupposeClaim1’sconverseiftruei.e.,
Converseofclaim1:ifniscompositethenits
notthecasethatforallainZn*,an-1=1modn.
i.e.,thereexistsatleastoneainZn*suchthat
a≠1modn.
i.e.,thereexistsatleastoneainZn*suchthat
an-1≠1modn.
Inotherwords,ifaiscompositethenthere
existsanainZn*suchthatan-1≠1modn.
Theconverseofclaimoneisnottrue,theredo
existcarmichaelnos.withthepropertythatfor
allainZn*,wehavean-1=1modn.
10
AGroupisapairconsistingofasetwithanoperation
definedonitsuchthatthegroupisclosedunderthe
operation,theoperationisassociative,thegrouphas
anidentityelementwithrespecttotheoperationand
foreachelementinthesetthereexistsaninverse,such
thattheoperationonanelementanditsinverseyields
theidentityelement.
E.g.,Setofintegersunderbinaryadditionformsa
group(Z,+),i.e.,
Foranya,binZ,sum(a+b)isinZ
(a+b)+c=a+(b+c),i.e.,thesumisassociative
Thegrouphasanidentityelement0for+operation.
ForeachelementainZwehaveanelement–asuchthata+(-
a)=(-a)+a=0.
11
(Zn,+n)isagroup,where+nissummodulon.
Ifgcd(a,b)=g,wherea,b,&gareintegers,then
thereexistintegerssayx&ysuchthat
xa+yb=g
IfZn
*isasetofnumbersbetween1&n-1whichare
relativelyprimeton,then(Zn
*,*n)formsagroup.
12
IfGisafinitegroup&HisasubgroupofG
thensizeofGisdivisiblebysizeofH.
If(G,o)isagroup,HisasubsetofG,such
that(H,o)formsagroupthenHisasubgroup
ofG.
that(H,o)formsagroupthenHisasubgroup
ofG.
13
IfH=G,theproofistrivial.
LetH≠G,&H={h1,h2,h3,…….hk}
LetgєG-H,then
g1H={g1h1,g2h2,……….g1hk}g1H={g1h1,g2h2,……….g1hk}
g2H={g2h1,g2h2,……….g2hk}
.
.
gnH={gnh1,gnh2,…………gnhk}
Everytimewecreateknewelements(cosets).
14
Chooseano.auniformlyatrandomfrom
{1,2,..n-1}.
Ifgcd(a,n)≠1thenreturncomposite
ElseElse
computeb=an-1modn.
Ifb≠1thenreturncomposite
Else{aєZn*}
computeb=an-1modn
Ifb≠1thenreturncomposite
elsereturnprime
15
IfthereexistsanainZn*suchthatan-1≠1mod
nthenweclaimthatatleasthalfofthe
elementsofZn*satisfytheconditionthatan-1
≠1modn.
LetSbetheno.ofelementsinZn*suchthataє
Zn*,an-1≠1modn.
ThenH=Zn*-S={aєZn*,an-1≠1modn}
HformsasubgroupofZn*.
16
ConsidersetH={aєZn*:an-1=1modn}
1)aєH&bєH=>abєH
(ab)n-1=an-1bn-1=1modn
2)aєH=>an-1=1modn=(a-1)n-1=1modn2)aєH=>a=1modn=(a)=1modn
ThereforeHisasubgroupofZn*
|H|<=|Z|/2becauseHisastrictsubgroupofZn*
i.e.atleastoneelementinZn*doesn’tfallinH.So
maxsizeofHishalfofZn*.
17

Primality testing