From 73aecc642060cbe085523da1a7a367b031a7ac30 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sun, 1 Dec 2019 15:39:25 +0100 Subject: [PATCH] even simpler schemes and stuff --- pir/src/main/java/dk/au/pir/Driver.java | 24 ++++++++++++++- .../evenSimpler/evenSimplerClient.java | 30 +++++++++++++++++++ .../evenSimpler/evenSimplerDatabase.java | 17 +++++++++++ .../evenSimpler/evenSimplerServer.java | 22 ++++++++++++++ .../au/pir/protocols/simple/SimpleClient.java | 3 -- .../java/dk/au/pir/settings/PIRSettings.java | 9 +++++- 6 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerClient.java create mode 100644 pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerDatabase.java create mode 100644 pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerServer.java diff --git a/pir/src/main/java/dk/au/pir/Driver.java b/pir/src/main/java/dk/au/pir/Driver.java index 6bd8c4c..6f0374c 100644 --- a/pir/src/main/java/dk/au/pir/Driver.java +++ b/pir/src/main/java/dk/au/pir/Driver.java @@ -1,5 +1,8 @@ package dk.au.pir; +import dk.au.pir.protocols.evenSimpler.evenSimplerClient; +import dk.au.pir.protocols.evenSimpler.evenSimplerDatabase; +import dk.au.pir.protocols.evenSimpler.evenSimplerServer; import dk.au.pir.protocols.interpoly.InterPolyClient; import dk.au.pir.protocols.interpoly.InterPolyDatabase; import dk.au.pir.protocols.interpoly.InterPolyServer; @@ -12,6 +15,24 @@ import java.util.Arrays; public class Driver { + + private static int[] evenSimplerScheme(int record) { + PIRSettings settings = new PIRSettings(8, 1, 2); + evenSimplerDatabase database = new evenSimplerDatabase(settings, new int[] {0, 0, 0, 1, 0, 0, 0, 0}); + + evenSimplerServer[] servers = new evenSimplerServer[settings.getNumServers()]; + + for (int i = 0; i < settings.getNumServers(); i++) { + servers[i] = new evenSimplerServer(database, settings); + } + + evenSimplerClient client = new evenSimplerClient(settings, servers); + + int[] res = client.receiveBits(record); + System.out.println("res: " + Arrays.toString(res)); + return res; + } + private static int simpleScheme(int index) { PIRSettings settings = new PIRSettings(8, 2, 1); SimpleDatabase database = new SimpleDatabase(settings, new int[] {0, 0, 1, 0, 0, 0, 0, 0}); @@ -104,7 +125,8 @@ public class Driver { public static void main(String[] args) { // generalBlockInterPolyTestButBetter(1); - simpleBlockScheme(1); + //simpleBlockScheme(1); + evenSimplerScheme(1); /* int sum = 0; for (int i = 0; i < 1; i++) { diff --git a/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerClient.java b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerClient.java new file mode 100644 index 0000000..fe8342a --- /dev/null +++ b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerClient.java @@ -0,0 +1,30 @@ +package dk.au.pir.protocols.evenSimpler; + +import dk.au.pir.protocols.simple.SimpleServer; +import dk.au.pir.settings.PIRSettings; + +public class evenSimplerClient { + + + private final PIRSettings settings; + private final evenSimplerServer[] servers; + + public evenSimplerClient(PIRSettings settings, evenSimplerServer[] servers) { + this.settings = settings; + this.servers = servers; + } + + public int receiveBit(int index) { + int[] data = this.servers[0].giveDatabase(); + return data[index]; + } + + public int[] receiveBits(int record) { + int[] res = new int[settings.getBlocksize()]; + int[] data = this.servers[0].giveDatabase(); + + System.arraycopy(data, (record * settings.getBlocksize()), res, 0, settings.getBlocksize()); + + return res; + } +} diff --git a/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerDatabase.java b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerDatabase.java new file mode 100644 index 0000000..78da06e --- /dev/null +++ b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerDatabase.java @@ -0,0 +1,17 @@ +package dk.au.pir.protocols.evenSimpler; + + +import dk.au.pir.settings.PIRSettings; + +public class evenSimplerDatabase { + + private final int[] x; + + public evenSimplerDatabase(PIRSettings settings, int[] x) { + this.x = x; + } + + public int[] getX() { + return x; + } +} diff --git a/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerServer.java b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerServer.java new file mode 100644 index 0000000..5bab8ce --- /dev/null +++ b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/evenSimplerServer.java @@ -0,0 +1,22 @@ +package dk.au.pir.protocols.evenSimpler; + +import dk.au.pir.protocols.simple.SimpleDatabase; +import dk.au.pir.settings.PIRSettings; + +public class evenSimplerServer { + + private final evenSimplerDatabase database; + private final PIRSettings settings; + private final int[] x; + + public evenSimplerServer(evenSimplerDatabase database, PIRSettings settings) { + this.database = database; + this.settings = settings; + this.x = database.getX(); + } + + public int[] giveDatabase() { + return this.x; + } + +} diff --git a/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java b/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java index b880c26..1d31918 100644 --- a/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java +++ b/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java @@ -1,12 +1,9 @@ package dk.au.pir.protocols.simple; -import dk.au.pir.protocols.simple.SimpleServer; import dk.au.pir.settings.PIRSettings; -import java.util.ArrayList; import java.util.Random; -import static dk.au.pir.utils.ProtocolUtils.printIntArrayArray; public class SimpleClient { 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 0f3b83f..9dcfed2 100644 --- a/pir/src/main/java/dk/au/pir/settings/PIRSettings.java +++ b/pir/src/main/java/dk/au/pir/settings/PIRSettings.java @@ -21,7 +21,14 @@ public class PIRSettings { this.blocksize = blocksize; - this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize); + // TODO: lol + if (numServers > 1) { + this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize); + } else { + this.sequences = ProtocolUtils.createSequences(calculateS(2, databaseSize), 2, databaseSize); + } + + this.field = new BigIntegerField(); }