I'm having problems transposing this pseudo-code into something usable. Perhaps someone could lend a hand?
Pseudo-code:
What I have:Input: n > 2, an odd integer to be tested for primality;
Input: k, a parameter that determines the accuracy of the test
Output: composite if n is composite, otherwise probably prime
write n − 1 as 2s·d with d odd by factoring powers of 2 from n − 1
LOOP: repeat k times:
pick a randomly in the range [2, n − 1]
x = ad mod n
if x = 1 or x = n − 1 then do next LOOP
for r = 1 .. s − 1
x = x2 mod n
if x = 1 then return composite
if x = n − 1 then do next LOOP
return composite
return probably prime
I am manually assigning numbers for testing. I use "DoEvents" in case I end up with a run-away loop so I can stop it without a crash.Code:Private Sub Form_Load() Dim K As Long Dim N As Long Dim A As Long Dim X As Long Dim D As Long Dim Prime As Boolean N = 23 K = 11 D = 3 Prime = True For A = 3 To K Step 2 DoEvents X = (A * D) Mod N If X < (X ^ 2) Mod N Then If X = 1 Then Prime = False End If End If Next Debug.Print Prime End End Sub
![]()




Reply With Quote