Page MenuHomec4science

FragmentEncrypted.java
No OneTemporary

File Metadata

Created
Sun, Jan 5, 04:17

FragmentEncrypted.java

package crypto.elgamal.fragment;
import java.io.Serializable;
import java.math.BigInteger;
import org.bouncycastle.math.ec.ECPoint;
public class FragmentEncrypted implements Serializable {
private static final long serialVersionUID = -3696282821457016342L;
private ECPoint R;
private ECPoint S;
public FragmentEncrypted() {
this.R = null;
this.S = null;
}
public FragmentEncrypted(ECPoint R, ECPoint S) {
this.R = R;
this.S = S;
}
public ECPoint getR() {
return R;
}
public ECPoint getS() {
return S;
}
public FragmentEncoded getFragmentEncoded() {
return new FragmentEncoded(this);
}
public FragmentEncrypted add(FragmentEncrypted fragToAdd) {
ECPoint first;
ECPoint second;
// XXX beware shallow copy
if (this.R == null && this.S == null) {
first = fragToAdd.getR();
second = fragToAdd.getS();
}
else if (fragToAdd.getR() == null && fragToAdd.getS() == null) {
first = R;
second = S;
}
else {
first = R.add(fragToAdd.getR());
second = S.add(fragToAdd.getS());
}
return new FragmentEncrypted(first, second);
}
public FragmentEncrypted scale(BigInteger a) {
// TODO: check sanity of number
ECPoint first = R.multiply(a);
ECPoint second = S.multiply(a);
return new FragmentEncrypted(first, second);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((R == null) ? 0 : R.hashCode());
result = prime * result + ((S == null) ? 0 : S.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FragmentEncrypted other = (FragmentEncrypted) obj;
if (R == null) {
if (other.R != null)
return false;
} else if (!R.equals(other.R))
return false;
if (S == null) {
if (other.S != null)
return false;
} else if (!S.equals(other.S))
return false;
return true;
}
}

Event Timeline