Bruter.java

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

42

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

43

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

45

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

49

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

55

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

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

61

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

82

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

87

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

94

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

95

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

96

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

97

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

98

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

99

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

101

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

112

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

131

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

139

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

147

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