Bruter.java

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
Location : getRemainder
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
Replaced long subtraction with addition → KILLED

2.2
Location : getRemainder
Killed by : none
replaced long return with 0 for com/jsql/util/bruter/Bruter::getRemainder → SURVIVED

46

1.1
Location : getNumberOfPossibilities
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
negated conditional → KILLED

2.2
Location : getNumberOfPossibilities
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
changed conditional boundary → KILLED

47

1.1
Location : getNumberOfPossibilities
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
Replaced long addition with subtraction → KILLED

50

1.1
Location : getNumberOfPossibilities
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
replaced long return with 0 for com/jsql/util/bruter/Bruter::getNumberOfPossibilities → KILLED

54

1.1
Location : addLowerCaseLetters
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
changed conditional boundary → KILLED

2.2
Location : addLowerCaseLetters
Killed by : none
negated conditional → TIMED_OUT

3.3
Location : addLowerCaseLetters
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
Replaced integer addition with subtraction → KILLED

60

1.1
Location : addDigits
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : addDigits
Killed by : none
changed conditional boundary → SURVIVED

66

1.1
Location : addUpperCaseLetters
Killed by : none
Replaced integer addition with subtraction → SURVIVED

2.2
Location : addUpperCaseLetters
Killed by : none
negated conditional → TIMED_OUT

3.3
Location : addUpperCaseLetters
Killed by : none
changed conditional boundary → SURVIVED

91

1.1
Location : getPerSecond
Killed by : none
Replaced long division with multiplication → SURVIVED

100

1.1
Location : getPerSecond
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_3]
replaced int return with 0 for com/jsql/util/bruter/Bruter::getPerSecond → KILLED

113

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced integer division with multiplication → KILLED

114

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced integer modulus with multiplication → KILLED

115

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced integer division with multiplication → KILLED

116

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced integer modulus with multiplication → KILLED

117

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced integer division with multiplication → KILLED

118

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced integer modulus with multiplication → KILLED

120

1.1
Location : calculateTimeElapsed
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
replaced return value with "" for com/jsql/util/bruter/Bruter::calculateTimeElapsed → KILLED

130

1.1
Location : calculateTimeDifference
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced double multiplication with division → KILLED

2.2
Location : calculateTimeDifference
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_3]
Replaced long subtraction with addition → KILLED

3.3
Location : calculateTimeDifference
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
replaced long return with 0 for com/jsql/util/bruter/Bruter::calculateTimeDifference → KILLED

4.4
Location : calculateTimeDifference
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_4]
Replaced double multiplication with division → KILLED

149

1.1
Location : isFound
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
replaced boolean return with true for com/jsql/util/bruter/Bruter::isFound → KILLED

2.2
Location : isFound
Killed by : none
replaced boolean return with false for com/jsql/util/bruter/Bruter::isFound → TIMED_OUT

157

1.1
Location : isPaused
Killed by : none
replaced boolean return with true for com/jsql/util/bruter/Bruter::isPaused → NO_COVERAGE

2.2
Location : isPaused
Killed by : none
replaced boolean return with false for com/jsql/util/bruter/Bruter::isPaused → NO_COVERAGE

165

1.1
Location : getCounter
Killed by : none
replaced int return with 0 for com/jsql/util/bruter/Bruter::getCounter → NO_COVERAGE

169

1.1
Location : getMaxLength
Killed by : none
replaced int return with 0 for com/jsql/util/bruter/Bruter::getMaxLength → NO_COVERAGE

173

1.1
Location : getMinLength
Killed by : none
replaced int return with 0 for com/jsql/util/bruter/Bruter::getMinLength → NO_COVERAGE

181

1.1
Location : isDone
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_3]
replaced boolean return with true for com/jsql/util/bruter/Bruter::isDone → KILLED

2.2
Location : isDone
Killed by : none
replaced boolean return with false for com/jsql/util/bruter/Bruter::isDone → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT 1.16.1