1
0
Fork 0

Det var det.

This commit is contained in:
Thomas 2019-11-20 16:47:15 +01:00
parent 8e5bbaa8ac
commit 306f2d660b
4 changed files with 29 additions and 11 deletions

View file

@ -5,13 +5,15 @@ import dk.au.pir.protocols.interpoly.InterPolyDatabase;
import dk.au.pir.protocols.interpoly.InterPolyServer; import dk.au.pir.protocols.interpoly.InterPolyServer;
import dk.au.pir.settings.PIRSettings; import dk.au.pir.settings.PIRSettings;
import java.util.Arrays;
public class Driver { public class Driver {
private static int generalInterPolyTest(int index) { private static int[] generalInterPolyTest(int index) {
PIRSettings settings = new PIRSettings(8, 3); PIRSettings settings = new PIRSettings(8, 3, 2);
int s = settings.getS(); int s = settings.getS();
System.out.println("s is: " + s); System.out.println("s is: " + s);
InterPolyDatabase database = new InterPolyDatabase(settings); InterPolyDatabase database = new InterPolyDatabase(settings, new int[] {0,0, 1,0, 0,0, 0,1});
InterPolyServer[] servers = new InterPolyServer[settings.getNumServers()]; InterPolyServer[] servers = new InterPolyServer[settings.getNumServers()];
for (int i = 0; i < settings.getNumServers(); i++) { for (int i = 0; i < settings.getNumServers(); i++) {
@ -19,13 +21,13 @@ public class Driver {
} }
InterPolyClient client = new InterPolyClient(settings, servers); InterPolyClient client = new InterPolyClient(settings, servers);
int res = client.receive(index); int[] res = client.receive(index);
System.out.println("res: " + res); System.out.println("res: " + Arrays.toString(res));
return res; return res;
} }
public static void main(String[] args) { public static void main(String[] args) {
generalInterPolyTest(2); generalInterPolyTest(1);
/* /*
int sum = 0; int sum = 0;
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {

View file

@ -46,7 +46,7 @@ public class InterPolyClient {
} }
public int receive(int index) { private int receiveBit(int index) {
FieldElement[] randoms = this.getRandomFieldElements(); FieldElement[] randoms = this.getRandomFieldElements();
FieldElement[] Fs = new FieldElement[this.servers.length]; FieldElement[] Fs = new FieldElement[this.servers.length];
for (int z = 0; z < this.servers.length; z++) { for (int z = 0; z < this.servers.length; z++) {
@ -55,4 +55,12 @@ public class InterPolyClient {
FieldElement res = FieldElementLagrange.interpolate(this.field, Fs); FieldElement res = FieldElementLagrange.interpolate(this.field, Fs);
return res.getValue().intValue(); return res.getValue().intValue();
} }
public int[] receive(int record) {
int[] results = new int[settings.getBlocksize()];
for (int i = 0; i < settings.getBlocksize(); i++) {
results[i] = this.receiveBit((settings.getBlocksize() * record) + i);
}
return results;
}
} }

View file

@ -5,9 +5,9 @@ import dk.au.pir.settings.PIRSettings;
public class InterPolyDatabase { public class InterPolyDatabase {
private final int[] x; private final int[] x;
public InterPolyDatabase(PIRSettings settings) { public InterPolyDatabase(PIRSettings settings, int[] x) {
this.x = new int[settings.getDatabaseSize()]; //this.x = new int[settings.getDatabaseSize() * settings.getBlocksize()];
this.x[2] = 1; this.x = x;
} }
public int[] getX() { public int[] getX() {

View file

@ -12,10 +12,14 @@ public class PIRSettings {
private final int[][] sequences; private final int[][] sequences;
private final BigIntegerField field; private final BigIntegerField field;
public PIRSettings(int databaseSize, int numServers) { private final int blocksize;
public PIRSettings(int databaseSize, int numServers, int blocksize) {
this.databaseSize = databaseSize; this.databaseSize = databaseSize;
this.numServers = numServers; this.numServers = numServers;
this.s = calculateS(numServers, databaseSize); this.s = calculateS(numServers, databaseSize);
this.blocksize = blocksize;
this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize); this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize);
this.field = new BigIntegerField(); this.field = new BigIntegerField();
@ -49,4 +53,8 @@ public class PIRSettings {
public BigIntegerField getField() { public BigIntegerField getField() {
return field; return field;
} }
public int getBlocksize() {
return this.blocksize;
}
} }