Page MenuHomec4science

Test.java
No OneTemporary

File Metadata

Created
Tue, Jan 7, 01:34

Test.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package crypto.dgk;
import java.math.BigInteger;
import crypto.CryptoException;
/**
*
* @author raisaro
*/
public class Test {
public static void main(String[] args) throws CryptoException{
System.out.println("Test starts...");
int l = 16;
int t = 160;
int k = 1024;
DGK_key_generator kg = new DGK_key_generator(k, t, l);
kg.generateKeys();
BigInteger[] pk = {kg.getN(), kg.getG(), kg.getH(), kg.getU()};
BigInteger[] sk = {kg.getP(), kg.getQ(), kg.getVpvq(), kg.getPp_inv(), kg.getQq_inv()};
System.out.println("Key have been succesfully generated!");
System.out.println("u = " + kg.getU());
System.out.println("DGK-scheme generation");
DGK_scheme s = new DGK_scheme(pk, sk, k, t, l);
BigInteger message1 = BigInteger.valueOf(2);
System.out.println("Encryption of " + message1);
BigInteger c1 = s.encryption(message1);
System.out.println("Decryption of " + c1);
boolean res = s.decryptionZero(c1);
System.out.println("The encrypted value is zero? " + res);
BigInteger m = s.decryption(c1);
System.out.println("Result = " + m);
System.out.println("Homomorphic test");
BigInteger message2 = BigInteger.valueOf(3);
BigInteger c2 = s.encryption(message2);
BigInteger c3 = c1.modPow(message2 ,kg.getN());
BigInteger m2 = s.decryption(c3);
BigInteger message4 = BigInteger.valueOf(2);
BigInteger c4 = s.encryption(message4);
BigInteger message5 = BigInteger.valueOf(3);
BigInteger c5 = s.encryption(message5);
BigInteger c6 = c4.multiply(c5);
BigInteger c7 = c6.multiply(c3).mod(kg.getN());
BigInteger m7 = s.decryption(c7);
System.out.println("Result = " + m7);
}
}

Event Timeline