From 306f2d660bc01733aba347847d0522b5b01a894f Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Nov 2019 16:47:15 +0100 Subject: [PATCH] Det var det. --- pir/src/main/java/dk/au/pir/Driver.java | 14 ++++++++------ .../pir/protocols/interpoly/InterPolyClient.java | 10 +++++++++- .../pir/protocols/interpoly/InterPolyDatabase.java | 6 +++--- .../main/java/dk/au/pir/settings/PIRSettings.java | 10 +++++++++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/pir/src/main/java/dk/au/pir/Driver.java b/pir/src/main/java/dk/au/pir/Driver.java index 83798b5..ac7002e 100644 --- a/pir/src/main/java/dk/au/pir/Driver.java +++ b/pir/src/main/java/dk/au/pir/Driver.java @@ -5,13 +5,15 @@ import dk.au.pir.protocols.interpoly.InterPolyDatabase; import dk.au.pir.protocols.interpoly.InterPolyServer; import dk.au.pir.settings.PIRSettings; +import java.util.Arrays; + public class Driver { - private static int generalInterPolyTest(int index) { - PIRSettings settings = new PIRSettings(8, 3); + private static int[] generalInterPolyTest(int index) { + PIRSettings settings = new PIRSettings(8, 3, 2); int s = settings.getS(); 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()]; for (int i = 0; i < settings.getNumServers(); i++) { @@ -19,13 +21,13 @@ public class Driver { } InterPolyClient client = new InterPolyClient(settings, servers); - int res = client.receive(index); - System.out.println("res: " + res); + int[] res = client.receive(index); + System.out.println("res: " + Arrays.toString(res)); return res; } public static void main(String[] args) { - generalInterPolyTest(2); + generalInterPolyTest(1); /* int sum = 0; for (int i = 0; i < 1; i++) { diff --git a/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java b/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java index a1494d3..a632c05 100644 --- a/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java +++ b/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java @@ -46,7 +46,7 @@ public class InterPolyClient { } - public int receive(int index) { + private int receiveBit(int index) { FieldElement[] randoms = this.getRandomFieldElements(); FieldElement[] Fs = new FieldElement[this.servers.length]; for (int z = 0; z < this.servers.length; z++) { @@ -55,4 +55,12 @@ public class InterPolyClient { FieldElement res = FieldElementLagrange.interpolate(this.field, Fs); 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; + } } diff --git a/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyDatabase.java b/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyDatabase.java index 49c8478..9c96c59 100644 --- a/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyDatabase.java +++ b/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyDatabase.java @@ -5,9 +5,9 @@ import dk.au.pir.settings.PIRSettings; public class InterPolyDatabase { private final int[] x; - public InterPolyDatabase(PIRSettings settings) { - this.x = new int[settings.getDatabaseSize()]; - this.x[2] = 1; + public InterPolyDatabase(PIRSettings settings, int[] x) { + //this.x = new int[settings.getDatabaseSize() * settings.getBlocksize()]; + this.x = x; } public int[] getX() { diff --git a/pir/src/main/java/dk/au/pir/settings/PIRSettings.java b/pir/src/main/java/dk/au/pir/settings/PIRSettings.java index 93a10f4..0f3b83f 100644 --- a/pir/src/main/java/dk/au/pir/settings/PIRSettings.java +++ b/pir/src/main/java/dk/au/pir/settings/PIRSettings.java @@ -12,10 +12,14 @@ public class PIRSettings { private final int[][] sequences; 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.numServers = numServers; this.s = calculateS(numServers, databaseSize); + this.blocksize = blocksize; + this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize); this.field = new BigIntegerField(); @@ -49,4 +53,8 @@ public class PIRSettings { public BigIntegerField getField() { return field; } + + public int getBlocksize() { + return this.blocksize; + } }