-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSignatures.java
74 lines (72 loc) · 2.28 KB
/
TestSignatures.java
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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.security.SecureRandom;
class TestSignatures {
private ArrayList<String> sigList=new ArrayList<>();
private static final String sigFileNames[]={"sig1.txt","sig2.txt","sig3.txt"};
private static int sigCounter=0;
private void generateRandomSigFile(String fileName) throws IOException {
int len=sigList.size();
File file=new File("Signatures",fileName);
FileWriter fileWriter=new FileWriter(file);
boolean flag[]=new boolean[len];
for(int i=0;i<len;++i) {
int r=new SecureRandom().nextInt(len);
if(!flag[r]) {
fileWriter.write(sigList.get(r)+"\n");
flag[r]=true;
}
else
--i;
}
fileWriter.close();
}
private static void testSignatures() throws IOException, InterruptedException {
SecureRandom secureRandom=new SecureRandom();
int fileNumber=secureRandom.nextInt(sigFileNames.length);
TestSignatures ts=new TestSignatures();
ts.readSigFile(sigFileNames[fileNumber]);
int len=ts.sigList.size();
int sigNumber=secureRandom.nextInt(len);
String userName=ts.sigList.get(sigNumber);
String passwd;
switch(userName) {
case "admin": passwd="1234";
break;
case "foo": passwd="5678";
break;
case "bar": passwd="3421";
break;
default: passwd=ts.sigList.get(secureRandom.nextInt(len));
}
System.out.println("Username= "+userName+"\nPassword= "+passwd);
String x[]={"python","login.py",userName,passwd};
new ProcessBuilder(x).start().waitFor();
}
private void readSigFile(String fileName) throws IOException {
File file=new File("Signatures",fileName);
BufferedReader br=new BufferedReader(new FileReader(file));
String signatures;
while((signatures=br.readLine())!=null) {
sigList.add(signatures);
}
br.close();
}
public static void main(String args[]) {
try {
TestSignatures ts=new TestSignatures();
ts.readSigFile(sigFileNames[0]);
ts.generateRandomSigFile(sigFileNames[1]);
ts.generateRandomSigFile(sigFileNames[2]);
int len=ts.sigList.size()*3;
while(sigCounter++<=len)
testSignatures();
}catch(IOException|InterruptedException e) {
e.printStackTrace();
}
}
}