Skip to content

Commit c6c8525

Browse files
committed
Add big integer multiply modification
1 parent 454e80d commit c6c8525

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ release.properties
77
dependency-reduced-pom.xml
88
buildNumber.properties
99
.mvn/timing.properties
10-
/nbproject/
10+
/nbproject/
11+
*.idea/
12+
ModifiableVariable.iml
13+
.classpath
14+
.factorypath
15+
.project
16+
.settings/

src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import de.rub.nds.modifiablevariable.biginteger.BigIntegerAddModification;
1212
import de.rub.nds.modifiablevariable.biginteger.BigIntegerExplicitValueModification;
1313
import de.rub.nds.modifiablevariable.biginteger.BigIntegerInteractiveModification;
14+
import de.rub.nds.modifiablevariable.biginteger.BigIntegerMultiplyModification;
1415
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftLeftModification;
1516
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftRightModification;
1617
import de.rub.nds.modifiablevariable.biginteger.BigIntegerSubtractModification;
@@ -75,6 +76,7 @@ public abstract class ModifiableVariable<E> implements Serializable {
7576
@XmlElement(type = BigIntegerExplicitValueModification.class, name = "BigIntegerExplicitValueModification"),
7677
@XmlElement(type = BigIntegerAddModification.class, name = "BigIntegerAddModification"),
7778
@XmlElement(type = BigIntegerInteractiveModification.class, name = "BigIntegerInteractiveModification"),
79+
@XmlElement(type = BigIntegerMultiplyModification.class, name = "BigIntegerMultiplyModification"),
7880
@XmlElement(type = BooleanToggleModification.class, name = "BooleanToggleModification"),
7981
@XmlElement(type = BooleanExplicitValueModification.class, name = "BooleanExplicitValueModification"),
8082
@XmlElement(type = ByteArrayXorModification.class, name = "ByteArrayXorModification"),
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* ModifiableVariable - A Variable Concept for Runtime Modifications
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.modifiablevariable.biginteger;
10+
11+
import de.rub.nds.modifiablevariable.VariableModification;
12+
import java.math.BigInteger;
13+
import java.util.Objects;
14+
import java.util.Random;
15+
import javax.xml.bind.annotation.XmlAccessType;
16+
import javax.xml.bind.annotation.XmlAccessorType;
17+
import javax.xml.bind.annotation.XmlRootElement;
18+
import javax.xml.bind.annotation.XmlType;
19+
20+
@XmlRootElement
21+
@XmlType(propOrder = { "factor", "modificationFilter" })
22+
@XmlAccessorType(XmlAccessType.FIELD)
23+
public class BigIntegerMultiplyModification extends VariableModification<BigInteger> {
24+
25+
private final static int MAX_FACTOR_LENGTH = 8;
26+
27+
private BigInteger factor;
28+
29+
public BigIntegerMultiplyModification() {
30+
31+
}
32+
33+
public BigIntegerMultiplyModification(BigInteger bi) {
34+
this.factor = bi;
35+
}
36+
37+
@Override
38+
protected BigInteger modifyImplementationHook(BigInteger input) {
39+
if (input == null) {
40+
input = BigInteger.ZERO;
41+
}
42+
return input.multiply(factor);
43+
}
44+
45+
public BigInteger getFactor() {
46+
return factor;
47+
}
48+
49+
public void setFactor(BigInteger factor) {
50+
this.factor = factor;
51+
}
52+
53+
@Override
54+
public VariableModification<BigInteger> getModifiedCopy() {
55+
return new BigIntegerMultiplyModification(factor.add(new BigInteger(MAX_FACTOR_LENGTH, new Random())));
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
int hash = 5;
61+
hash = 61 * hash + Objects.hashCode(this.factor);
62+
return hash;
63+
}
64+
65+
@Override
66+
public boolean equals(Object obj) {
67+
if (this == obj) {
68+
return true;
69+
}
70+
if (obj == null) {
71+
return false;
72+
}
73+
if (getClass() != obj.getClass()) {
74+
return false;
75+
}
76+
final BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj;
77+
if (!Objects.equals(this.factor, other.factor)) {
78+
return false;
79+
}
80+
return true;
81+
}
82+
}

0 commit comments

Comments
 (0)