-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.java
More file actions
95 lines (90 loc) · 4.67 KB
/
Copy pathDriver.java
File metadata and controls
95 lines (90 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.io.*;
import java.util.*;
import java.math.*;
import src.millerrabin.*;
import src.semiprime.*;
import src.dixon.*;
import src.pollardrho.*;
import src.logicalmatrix.*;
import java.util.concurrent.TimeUnit;
/**
* Class Used to run all aspects of the program at once
*/
class Driver {
//Start clock
public static long startTime;
public static long endTime;
public static long timeElapsedMillis;
public static long timeElapsedSeconds;
public static void main(String[] args)
{
boolean running = true;
Scanner kbReader = new Scanner(System.in);
int threads = 0;
while(threads < 1 || threads > 8) //Make sure it's a reasonable number of cores
{
System.out.println("Please enter the number of cores (1-8) available. To quit, type 0: "); //Ask for number of threads
threads = kbReader.nextInt(); //Call that number "threads"
}
while(running)
{
System.out.println("Please enter a number for factor testing. To quit, type 0: "); //Ask for test number
BigInteger testNumber = kbReader.nextBigInteger(); //Call that number "testNumber"
if(testNumber.equals(BigInteger.ZERO)) //If 0 then quit
{
System.out.println("Program terminated.");
running=false;
break;
} else
{
System.out.println("-----MILLER-RABIN PRIMALITY TEST-----"); //Run Miller-Rabin
startTime = System.currentTimeMillis();
boolean isComposite = !MillerRabin.runFromDriver(testNumber, threads);
System.out.println(testNumber + " is composite? " + isComposite);
endTime = System.currentTimeMillis();
timeElapsedMillis = TimeUnit.MILLISECONDS.toMillis(endTime - startTime);
System.out.println("This calculation took " + timeElapsedMillis + " milliseconds."); //Print time
if(isComposite) //If composite
{
System.out.println("-----SEMI-PRIME TEST-----"); //Run Semi-Prime
startTime = System.currentTimeMillis();
System.out.println(testNumber + " is semi-prime? " + SemiPrime.runFromDriver(testNumber, threads));
endTime = System.currentTimeMillis();
timeElapsedMillis = TimeUnit.MILLISECONDS.toMillis(endTime - startTime);
System.out.println("This calculation took " + timeElapsedMillis + " milliseconds."); //Print time
System.out.println("-----POLLARD-RHO FACTORIZATION ALGORITHM-----"); //Run Pollard's Rho
startTime = System.currentTimeMillis();
System.out.println("The factors of " + testNumber + " via Pollard-Rho are " + PollardRho.runFromDriver(testNumber));
endTime = System.currentTimeMillis();
timeElapsedMillis = TimeUnit.MILLISECONDS.toMillis(endTime - startTime);
System.out.println("This calculation took " + timeElapsedMillis + " milliseconds."); //Print time
System.out.println("-----DIXON FACTORIZATION ALGORITHM-----"); //Run Dixon
startTime = System.currentTimeMillis();
System.out.println("The factors of " + testNumber + " via Dixon are " + Dixon.runFromDriver(testNumber, threads));
endTime = System.currentTimeMillis();
timeElapsedMillis = TimeUnit.MILLISECONDS.toMillis(endTime - startTime);
System.out.println("This calculation took " + timeElapsedMillis + " milliseconds."); //Print time
}
else
{
System.out.println("The number is prime and thus cannot be semi-prime. It's factors are 1 & itself."); //If prime, cannot factor
}
}
System.out.println("Please enter a number for matrix testing. To quit, type 0: "); //Ask for matrix dimension
int matrixSize = kbReader.nextInt();
if(matrixSize == 0) //If 0 then quit
{
System.out.println("Program terminated.");
running=false;
} else
{
System.out.println("-----LOGICAL MATRIX MULTIPLICATION-----"); //Run matrix multiplication
startTime = System.currentTimeMillis();
LogicalMatrixMultiply.runFromDriver(matrixSize, threads);
endTime = System.currentTimeMillis();
timeElapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(endTime - startTime);
System.out.println("This calculation took " + timeElapsedSeconds + " seconds."); //Print time
}
}
}
}