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
37
    public long getRemainder() {
38 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;
39
    }
40
41
    public long getNumberOfPossibilities() {
42
        long possibilities = 0;
43 2 1. getNumberOfPossibilities : negated conditional → KILLED
2. getNumberOfPossibilities : changed conditional boundary → KILLED
        for (int i = this.minLength ; i <= this.maxLength ; i++) {
44 1 1. getNumberOfPossibilities : Replaced long addition with subtraction → KILLED
            possibilities += (long) Math.pow(this.characters.size(), i);
45
        }
46 1 1. getNumberOfPossibilities : replaced long return with 0 for com/jsql/util/bruter/Bruter::getNumberOfPossibilities → KILLED
        return possibilities;
47
    }
48
49
    public void addLowerCaseLetters() {
50 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++) {
51
            this.characters.add(String.valueOf(c));
52
        }
53
    }
54
55
    public void addDigits() {
56 2 1. addDigits : changed conditional boundary → SURVIVED
2. addDigits : negated conditional → TIMED_OUT
        for (var c = 0 ; c <= 9 ; c++) {
57
            this.characters.add(String.valueOf(c));
58
        }
59
    }
60
61
    public void addUpperCaseLetters() {
62 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++) {
63
            this.characters.add(String.valueOf(c));
64
        }
65
    }
66
67
    public void addSpecialCharacters() {
68
        for (char c: Bruter.specialCharacters) {
69
            this.characters.add(String.valueOf(c));
70
        }
71
    }
72
73
    public void excludeChars(String s) {
74
        char[] arrayChars = s.toCharArray();
75
        for (char arrayChar: arrayChars) {
76
            this.characters.remove(Character.toString(arrayChar));
77
        }
78
    }
79
80
    public int getPerSecond() {
81
        int i;
82
        try {
83 1 1. getPerSecond : Replaced long division with multiplication → SURVIVED
            i = (int) (this.count / this.calculateTimeDifference());
84
        } catch (Exception e) {
85
            LOGGER.log(LogLevelUtil.IGNORE, e);
86
            return 0;  // Ignore division by zero
87
        }
88 1 1. getPerSecond : replaced int return with 0 for com/jsql/util/bruter/Bruter::getPerSecond → KILLED
        return i;
89
    }
90
91
    public String calculateTimeElapsed() {
92
        long timeTaken = this.calculateTimeDifference();
93
        
94
        int seconds = (int) timeTaken;
95
        
96
        var minutes = 0;
97
        var hours = 0;
98
        var days = 0;
99
        
100 1 1. calculateTimeElapsed : Replaced integer division with multiplication → KILLED
        minutes = seconds / 60;
101 1 1. calculateTimeElapsed : Replaced integer modulus with multiplication → KILLED
        seconds = seconds % 60;
102 1 1. calculateTimeElapsed : Replaced integer division with multiplication → KILLED
        hours = minutes / 60;
103 1 1. calculateTimeElapsed : Replaced integer modulus with multiplication → KILLED
        minutes = minutes % 60;
104 1 1. calculateTimeElapsed : Replaced integer division with multiplication → KILLED
        days = hours / 24;
105 1 1. calculateTimeElapsed : Replaced integer modulus with multiplication → KILLED
        hours = hours % 24;
106
        
107 1 1. calculateTimeElapsed : replaced return value with "" for com/jsql/util/bruter/Bruter::calculateTimeElapsed → KILLED
        return String.format(
108
            "Time elapsed: %sdays %sh %smin %ss",
109
            days,
110
            hours,
111
            minutes,
112
            seconds
113
        );
114
    }
115
116
    private long calculateTimeDifference() {
117 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));
118
    }
119
    
120
    
121
    // Getter and setter
122
123
    public synchronized void setEndtime(long endtime) {
124
        this.endtime = endtime;
125
    }
126
127
    public void setMaxLength(int maxLength) {
128
        this.maxLength = maxLength;
129
    }
130
131
    public void setMinLength(int minLength) {
132
        this.minLength = minLength;
133
    }
134
135
    public boolean isFound() {
136 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;
137
    }
138
139
    public void setFound(boolean found) {
140
        this.found = found;
141
    }
142
143
    public int getCounter() {
144 1 1. getCounter : replaced int return with 0 for com/jsql/util/bruter/Bruter::getCounter → NO_COVERAGE
        return this.count;
145
    }
146
147
    public void setIsDone(Boolean done) {
148
        this.done = done;
149
    }
150
151
    public boolean isDone() {
152 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;
153
    }
154
}

Mutations

38

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
Covering tests

43

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

44

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

46

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

50

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

56

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

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

62

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

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

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

83

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

88

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

100

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

101

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

102

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

103

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

104

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

105

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

107

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

117

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_4]
replaced long return with 0 for com/jsql/util/bruter/Bruter::calculateTimeDifference → KILLED

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

136

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

144

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

152

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.19.1