Page MenuHomec4science

FragmentEncryptedTest.java
No OneTemporary

File Metadata

Created
Tue, Jan 7, 00:40

FragmentEncryptedTest.java

package crypto.elgamal.fragment;
import static org.junit.Assert.*;
import java.math.BigInteger;
import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.junit.Test;
import crypto.elgamal.ECElGamal;
public class FragmentEncryptedTest {
@Test
public void testAdd() {
ECElGamal eccegScheme = new ECElGamal(NISTNamedCurves.getByName("P-384"));
eccegScheme.initReverseDLTable();
BigInteger msg1 = new BigInteger("4");
BigInteger msg2 = new BigInteger("7");
FragmentEncrypted fragEncrypted1 = eccegScheme.encrypt(msg1);
FragmentEncrypted fragEncrypted2 = eccegScheme.encrypt(msg2);
FragmentEncrypted fragSum = fragEncrypted1.add(fragEncrypted2);
BigInteger sumDecrypted = eccegScheme.decrypt(fragSum);
assertTrue("Addition homomorphic", sumDecrypted.equals(msg1.add(msg2)));
}
@Test
public void testScale() {
ECElGamal eccegScheme = new ECElGamal(NISTNamedCurves.getByName("P-384"));
eccegScheme.initReverseDLTable();
BigInteger msg = new BigInteger("7");
BigInteger s = new BigInteger("3");
FragmentEncrypted frag = eccegScheme.encrypt(msg);
FragmentEncrypted fragScaled = frag.scale(s);
BigInteger msgScaled = eccegScheme.decrypt(fragScaled);
assertTrue("Scale homomorphic", msgScaled.equals(msg.multiply(s)));
}
}

Event Timeline