Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Miller Rabin
SUBMITTED BY:
Guest
DATE:
May 19, 2013, 4:02 a.m.
FORMAT:
Python
SIZE:
724 Bytes
Raw
Download
Tweet
HITS:
2014
Go to comments
Report
def
exercise4
(
n
,
k
):
''' Miller-Rabin procedure '''
d
=
n
-
1
s
=
0
while
d
%
2
==
0
and
d
!=
1
:
d
=
d
//
2
s
=
s
+
1
while
k
>
0
:
k
=
k
-
1
;
a
=
random
.
randint
(
2
,
n
-
2
)
x
=
a
**
d
%
n
#exercise3 (a,d,n)
if
x
==
1
or
x
==
n
-
1
:
continue
list
=
range
(
1
,
s
)
for
r
in
list
:
x
=
x
**
2
%
n
if
x
==
1
:
return
"composite"
if
x
==
n
-
1
:
continue
return
"composite"
return
"prime"
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus