Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private NativeMe As JavaObject
End Sub
Sub Globals
End Sub
Sub Activity_Create(firsttime As Boolean)
NativeMe.InitializeContext
Run_Test(False,100) 'B4A code
Run_Test(True,100) 'Inline Java call
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Run_Test( inline As Boolean, num_times As Int)
Dim bitlen As Int = 16 'Dim bitlen As Int =1022
Dim k As BigInteger, b As String, j As Int
k.Initialize("0")
For j=1 To num_times
If inline=False Then
k.ProbablePrime(bitlen) 'Generate 1024 bit probable prime
b=k.ToStringBase(2) 'Convert to binary string
Else
b=NativeMe.RunMethod("NewBigInt",Array(bitlen))
End If
'List leading bits.
Log("ProbablePrime " & j & " (Length = " & b.Length & " bits) First 8 bits " & b.SubString2(0,8) )
Next
End Sub
#If java
import android.util.Log;
import java.math.BigInteger;
import java.util.Random;
public String NewBigInt( int num_bits){
BigInteger bg ;
String s;
Random rnd = new java.util.Random();
bg = BigInteger.probablePrime(num_bits,rnd);
s=bg.toString(2);
return s;
}
#End If