dewisetia

0 Reputation

0 Badges

13 years, 125 days

MaplePrimes Activity


These are answers submitted by dewisetia

May be this program can useful for miller-rabin. I read pseudocode on Handbook of Applied Cryptography.

restart:
Miller_Rabin := proc(n, t)
local minus1, r, d, fact, ada, s, i, a, y, j;
minus1 := n-1;
r := minus1;

while ((r mod 2) = 0) do r := r/2; end do;
r := r;
d := minus1/r;
fact := ifactor(d);
ada := nops(fact);

if ada = 1 then s := 1; else s := op(2, fact); end if;
s := s;

for i from 1 to t do
a := rand(2 .. minus1)();
y := Power(a, r) mod n;

if (y <> 1) and (y <> minus1) then
j := 1;

while (j <> s-1) and (y <> minus1) do
y := y^2 mod n;

if y = 1 then printf("%a is a composite", n); return ();
j := j+1;
end if;

end do;
if y <> n-1 then printf("%a is a composite", n); return(); end if;

else printf("%a is a prime", n); return ();
end if;

end do;
end proc;

Page 1 of 1