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