1 | package com.jsql.util.bruter; | |
2 | ||
3 | import com.jsql.util.LogLevelUtil; | |
4 | import org.apache.logging.log4j.LogManager; | |
5 | import org.apache.logging.log4j.Logger; | |
6 | ||
7 | import java.util.ArrayList; | |
8 | import java.util.List; | |
9 | ||
10 | public class Bruter { | |
11 | | |
12 | /** | |
13 | * Log4j logger sent to view. | |
14 | */ | |
15 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
16 | ||
17 | protected final List<String> characters = new ArrayList<>(); | |
18 | | |
19 | protected boolean found = false; | |
20 | | |
21 | protected int maxLength; | |
22 | protected int minLength; | |
23 | | |
24 | protected int count; | |
25 | | |
26 | protected long starttime; | |
27 | protected long endtime; | |
28 | | |
29 | private static final char[] specialCharacters = { | |
30 | '~', '`', '!', '@', '#', '$', '%', '^', | |
31 | '&', '*', '(', ')', '_', '-', '+', '=', '{', '}', '[', ']', '|', '\\', | |
32 | ';', ':', '\'', '"', '<', '.', ',', '>', '/', '?', ' ' | |
33 | }; | |
34 | | |
35 | protected boolean done = false; | |
36 | protected boolean paused = false; | |
37 | ||
38 | public long getRemainder() { | |
39 |
2
1. getRemainder : replaced long return with 0 for com/jsql/util/bruter/Bruter::getRemainder → SURVIVED 2. getRemainder : Replaced long subtraction with addition → KILLED |
return this.getNumberOfPossibilities() - this.count; |
40 | } | |
41 | ||
42 | public long getNumberOfPossibilities() { | |
43 | | |
44 | long possibilities = 0; | |
45 | | |
46 |
2
1. getNumberOfPossibilities : negated conditional → KILLED 2. getNumberOfPossibilities : changed conditional boundary → KILLED |
for (int i = this.minLength; i <= this.maxLength; i++) { |
47 |
1
1. getNumberOfPossibilities : Replaced long addition with subtraction → KILLED |
possibilities += (long) Math.pow(this.characters.size(), i); |
48 | } | |
49 | | |
50 |
1
1. getNumberOfPossibilities : replaced long return with 0 for com/jsql/util/bruter/Bruter::getNumberOfPossibilities → KILLED |
return possibilities; |
51 | } | |
52 | ||
53 | public void addLowerCaseLetters() { | |
54 |
3
1. addLowerCaseLetters : negated conditional → TIMED_OUT 2. addLowerCaseLetters : changed conditional boundary → KILLED 3. addLowerCaseLetters : Replaced integer addition with subtraction → KILLED |
for (var c = 'a'; c <= 'z'; c++) { |
55 | this.characters.add(String.valueOf(c)); | |
56 | } | |
57 | } | |
58 | ||
59 | public void addDigits() { | |
60 |
2
1. addDigits : changed conditional boundary → SURVIVED 2. addDigits : negated conditional → TIMED_OUT |
for (var c = 0; c <= 9; c++) { |
61 | this.characters.add(String.valueOf(c)); | |
62 | } | |
63 | } | |
64 | ||
65 | public void addUpperCaseLetters() { | |
66 |
3
1. addUpperCaseLetters : Replaced integer addition with subtraction → SURVIVED 2. addUpperCaseLetters : changed conditional boundary → SURVIVED 3. addUpperCaseLetters : negated conditional → TIMED_OUT |
for (var c = 'A'; c <= 'Z'; c++) { |
67 | this.characters.add(String.valueOf(c)); | |
68 | } | |
69 | } | |
70 | ||
71 | public void addSpecialCharacters() { | |
72 | for (char c: specialCharacters) { | |
73 | this.characters.add(String.valueOf(c)); | |
74 | } | |
75 | } | |
76 | ||
77 | public void excludeChars(String s) { | |
78 | | |
79 | char[] arrayChars = s.toCharArray(); | |
80 | | |
81 | for (char arrayChar: arrayChars) { | |
82 | this.characters.remove(Character.toString(arrayChar)); | |
83 | } | |
84 | } | |
85 | ||
86 | public int getPerSecond() { | |
87 | | |
88 | int i; | |
89 | | |
90 | try { | |
91 |
1
1. getPerSecond : Replaced long division with multiplication → SURVIVED |
i = (int) (this.count / this.calculateTimeDifference()); |
92 | } catch (Exception e) { | |
93 | | |
94 | LOGGER.log(LogLevelUtil.IGNORE, e); | |
95 | | |
96 | // Ignore division by zero | |
97 | return 0; | |
98 | } | |
99 | | |
100 |
1
1. getPerSecond : replaced int return with 0 for com/jsql/util/bruter/Bruter::getPerSecond → KILLED |
return i; |
101 | } | |
102 | ||
103 | public String calculateTimeElapsed() { | |
104 | | |
105 | long timeTaken = this.calculateTimeDifference(); | |
106 | | |
107 | int seconds = (int) timeTaken; | |
108 | | |
109 | var minutes = 0; | |
110 | var hours = 0; | |
111 | var days = 0; | |
112 | | |
113 |
1
1. calculateTimeElapsed : Replaced integer division with multiplication → KILLED |
minutes = seconds / 60; |
114 |
1
1. calculateTimeElapsed : Replaced integer modulus with multiplication → KILLED |
seconds = seconds % 60; |
115 |
1
1. calculateTimeElapsed : Replaced integer division with multiplication → KILLED |
hours = minutes / 60; |
116 |
1
1. calculateTimeElapsed : Replaced integer modulus with multiplication → KILLED |
minutes = minutes % 60; |
117 |
1
1. calculateTimeElapsed : Replaced integer division with multiplication → KILLED |
days = hours / 24; |
118 |
1
1. calculateTimeElapsed : Replaced integer modulus with multiplication → KILLED |
hours = hours % 24; |
119 | | |
120 |
1
1. calculateTimeElapsed : replaced return value with "" for com/jsql/util/bruter/Bruter::calculateTimeElapsed → KILLED |
return String.format( |
121 | "Time elapsed: %sdays %sh %smin %ss", | |
122 | days, | |
123 | hours, | |
124 | minutes, | |
125 | seconds | |
126 | ); | |
127 | } | |
128 | ||
129 | private long calculateTimeDifference() { | |
130 |
4
1. calculateTimeDifference : Replaced double multiplication with division → KILLED 2. calculateTimeDifference : Replaced long subtraction with addition → KILLED 3. calculateTimeDifference : replaced long return with 0 for com/jsql/util/bruter/Bruter::calculateTimeDifference → KILLED 4. calculateTimeDifference : Replaced double multiplication with division → KILLED |
return (long) ((this.endtime - this.starttime) * (1 * Math.pow(10, -9))); |
131 | } | |
132 | | |
133 | | |
134 | // Getter and setter | |
135 | ||
136 | public synchronized void setEndtime(long endtime) { | |
137 | this.endtime = endtime; | |
138 | } | |
139 | ||
140 | public void setMaxLength(int maxLength) { | |
141 | this.maxLength = maxLength; | |
142 | } | |
143 | ||
144 | public void setMinLength(int minLength) { | |
145 | this.minLength = minLength; | |
146 | } | |
147 | ||
148 | public boolean isFound() { | |
149 |
2
1. isFound : replaced boolean return with false for com/jsql/util/bruter/Bruter::isFound → TIMED_OUT 2. isFound : replaced boolean return with true for com/jsql/util/bruter/Bruter::isFound → KILLED |
return this.found; |
150 | } | |
151 | ||
152 | public void setPaused(boolean paused) { | |
153 | this.paused = paused; | |
154 | } | |
155 | ||
156 | public boolean isPaused() { | |
157 |
2
1. isPaused : replaced boolean return with true for com/jsql/util/bruter/Bruter::isPaused → NO_COVERAGE 2. isPaused : replaced boolean return with false for com/jsql/util/bruter/Bruter::isPaused → NO_COVERAGE |
return this.paused; |
158 | } | |
159 | ||
160 | public void setFound(boolean found) { | |
161 | this.found = found; | |
162 | } | |
163 | ||
164 | public int getCounter() { | |
165 |
1
1. getCounter : replaced int return with 0 for com/jsql/util/bruter/Bruter::getCounter → NO_COVERAGE |
return this.count; |
166 | } | |
167 | ||
168 | public int getMaxLength() { | |
169 |
1
1. getMaxLength : replaced int return with 0 for com/jsql/util/bruter/Bruter::getMaxLength → NO_COVERAGE |
return this.maxLength; |
170 | } | |
171 | ||
172 | public int getMinLength() { | |
173 |
1
1. getMinLength : replaced int return with 0 for com/jsql/util/bruter/Bruter::getMinLength → NO_COVERAGE |
return this.minLength; |
174 | } | |
175 | ||
176 | public void setIsDone(Boolean done) { | |
177 | this.done = done; | |
178 | } | |
179 | ||
180 | public boolean isDone() { | |
181 |
2
1. isDone : replaced boolean return with false for com/jsql/util/bruter/Bruter::isDone → TIMED_OUT 2. isDone : replaced boolean return with true for com/jsql/util/bruter/Bruter::isDone → KILLED |
return this.done; |
182 | } | |
183 | } | |
Mutations | ||
39 |
1.1 2.2 |
|
46 |
1.1 2.2 |
|
47 |
1.1 |
|
50 |
1.1 |
|
54 |
1.1 2.2 3.3 |
|
60 |
1.1 2.2 |
|
66 |
1.1 2.2 3.3 |
|
91 |
1.1 |
|
100 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
118 |
1.1 |
|
120 |
1.1 |
|
130 |
1.1 2.2 3.3 4.4 |
|
149 |
1.1 2.2 |
|
157 |
1.1 2.2 |
|
165 |
1.1 |
|
169 |
1.1 |
|
173 |
1.1 |
|
181 |
1.1 2.2 |