Want more features on Pastebin? Sign Up, it's FREE!
Guest

Code

By: a guest on Jun 12th, 2013  |  syntax: VB.NET  |  size: 1.30 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Function Miller(ByVal p As Long, ByVal iteration As Integer) As Boolean
  2.         If p < 2 Then
  3.             Return False
  4.             Exit Function
  5.         ElseIf p <> 2 And p Mod 2 = 0 Then
  6.             Return False
  7.             Exit Function
  8.         Else
  9.  
  10.             Dim s As Long = p - 1
  11.             While s Mod 2 = 0
  12.                 s = s / 2
  13.             End While
  14.             For i = 1 To iteration
  15.                 Dim a As Long = Random(1, p - 1)
  16.                 Dim temp As Long = s
  17.                 Dim Modu As Long = (a Mod temp) Mod p
  18.                 While temp <> p - 1 And Modu <> 1 And Modu <> p - 1
  19.                     Modu = mulmod(Modu, Modu, p)
  20.                     temp = 2 * temp
  21.                 End While
  22.                 If Modu <> p - 1 And temp Mod 2 = 0 Then
  23.                     Return False
  24.                     Exit Function
  25.                 End If
  26.             Next
  27.             Return True
  28.         End If
  29.     End Function
  30.  
  31.  Function mulmod(ByVal a As Long, ByVal b As Long, ByVal c As Long) As Long
  32.         Dim x, y As Long
  33.         x = 0
  34.         y = a Mod c
  35.         While b > 0
  36.             If b Mod 2 = 1 Then
  37.                 x = (x + y) Mod c
  38.             End If
  39.             y = (y * 2) Mod c
  40.             b = b / 2
  41.         End While
  42.         Return x Mod c
  43.  
  44.  End Function
clone this paste RAW Paste Data