From 815a8d1d89c3cabe1668c106c84e93fddb9f0e39 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Fri, 13 Oct 2017 15:33:58 +0200 Subject: [PATCH] removed testing code --- src/ScharedSecret.java | 147 ----------------------------------------- src/ShamirsSecret.java | 124 ---------------------------------- src/test.html | 65 ------------------ 3 files changed, 336 deletions(-) delete mode 100644 src/ScharedSecret.java delete mode 100644 src/ShamirsSecret.java delete mode 100644 src/test.html diff --git a/src/ScharedSecret.java b/src/ScharedSecret.java deleted file mode 100644 index 0dd5fc7..0000000 --- a/src/ScharedSecret.java +++ /dev/null @@ -1,147 +0,0 @@ -import java.io.IOException; -import java.sql.Time; -import java.util.Random; - -public class ScharedSecret { - static Random rand=new Random(); - - public static int r10(){ - return rand.nextInt(10); - } - - public static int[] encodeBit(boolean bit){ - int threshold=22; - int dist=3; - - int low = threshold-dist; - int high = threshold+dist; - - int d1,d2,d3,d4,d5; - //System.out.println("\nbit: "+(bit?1:0)); - if (bit){ - //System.out.println("bounds: ["+threshold+"..."+high+"]"); - d1=r10(); - while(d1+18 0) return args[0]; - - try { - String secret = ""; - System.out.println("Please enter your secret:"); - int c; - while ((c = System.in.read()) != 10){ - secret+=(char)c; - } - return secret; - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - } - return null; - } - - public static void main(String[] args) { - String secret = secret(args); - String [] codes = { "", "", "", "", "" }; - System.out.print(" Binary: "); - for (int i=0; i(240+22)?1:0); - } - } - } -} diff --git a/src/ShamirsSecret.java b/src/ShamirsSecret.java deleted file mode 100644 index eeb23c8..0000000 --- a/src/ShamirsSecret.java +++ /dev/null @@ -1,124 +0,0 @@ -import java.security.InvalidParameterException; -import java.util.Random; -import java.util.Vector; - -public class ShamirsSecret { - private static Random rand = new Random(); - private static int prime = 257; - - public static int ggT(int a, int b){ - if (b<0) b=-b; - if (a==0) return b; - if (a<0) a=-a; - while (b != 0) if (a>b) a-=b; else b-=a; - return a; - } - - - public static class Quotient{ - int divident; - int divisor; - - public Quotient(int i) { - this.divident=i; - this.divisor=1; - } - - public Quotient(int divident,int divisor) throws InvalidParameterException{ - if (divisor == 0) throw new InvalidParameterException("Divisor of quotient must not be zero!"); - int ggt = ggT(divident,divisor); - if (divisor<0) ggt = -ggt; - this.divident=divident/ggt; - this.divisor=divisor/ggt; - } - - public Quotient times(Quotient q) throws InvalidParameterException{ - return new Quotient(divident * q.divident,divisor * q.divisor); - } - - public Quotient times(int f) throws InvalidParameterException{ - return new Quotient(f*divident,divisor); - } - - @Override - public String toString() { - return (divisor == 1) ? ""+divident : "["+divident+"/"+divisor+"]"; - } - - public int val() throws InvalidParameterException { - if (divisor != 1) throw new InvalidParameterException("Divisor should not be "+divisor); - return divident; - } - - public Quotient add(int i) throws InvalidParameterException{ - return add(new Quotient(i)); - } - - public Quotient add(Quotient q) throws InvalidParameterException { - return new Quotient(divident*q.divisor + divisor*q.divident,divisor*q.divisor); - } - - public int mod(int q) throws InvalidParameterException { - int inv = 1; - while ((divisor*inv)%q !=1)inv++; // search the inverse of the divisor - return (divident*inv)%q; - } - } - - public static class Share{ - private int x,y; - - public Share(int x, int[] coefficients) { - this.x=x; - int sum=0; - for (int i=0; i createSecrets(int secret, int count, int requires) { - Vector result = new Vector(); - - int [] coefficients = new int[requires]; - coefficients[0] = secret; - for (int i=1; i shares) throws InvalidParameterException{ - Quotient sum = new Quotient(0); - for (Share share_j:shares){ - Quotient prod = new Quotient(1); - for (Share share_m:shares){ - if (share_j == share_m) continue; - prod = prod.times(new Quotient(share_m.x,share_m.x-share_j.x)); - } - sum = sum.add(prod.times(share_j.y)); - } - return sum.mod(prime); - } - - public static void main(String[] args) throws InvalidParameterException { - int secret = rand.nextInt(255); - System.out.println(secret); - Vector shares = createSecrets(secret,5,3); - System.out.println(shares); - - shares.remove(0); - shares.remove(0); - System.out.println(shares); - - secret=reconstruct(shares); - System.out.println(secret); - } -} diff --git a/src/test.html b/src/test.html deleted file mode 100644 index acbd9ec..0000000 --- a/src/test.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - \ No newline at end of file -- 2.30.2