To test if an odd N is prime:
for loop1 to k do randomly select b from the set {1..N-1} if GCD(b,N)==1 and J(b,N)
b(N-1)/2(mod N) then continue looping else return not prime return prime with probability > 1-2-k
To calculate the value of J(x,y):
if x==1 then return 1 else if x is even then return J( x/2,y ) * (-1)(y2-1)/8 else return J( y(mod x),x ) * (-1)(x-1)(y-1)/4
To calculate the value of b(N-1)/2(mod N):
x(N-1)/2 y
b a
1 while x > 0 do if x is odd then a
ay(mod N) y
y2(mod N) x
floor(x/2) return a