Hi one and all.
Im doing a project on secret key protection n recovery. Im trying to implement SHAMIR's Secret scheme in java. The pblm im facing is that the secret key which can contain all types of characters(ascii values 0-127) when converted to number(integer) is having a length of more than 100 digits for 33+ characters. I cant limit my secret key to 5 or 4 characters but that kills the purpose. Im converting each character of the string into its ascii number, at the same time im making sure that each character corresponds to 3 digit integer by appending two 0's for the ascii values 0-9, a single 0 for the acsii values between 10-99. So i can club 3 digits to reconstruct the each character n finally the secret key.
But the pblm is that the number is becoming huge n i dunno how to handle it. I have to perform some arithmetic operations on that number, mainly addition. Im posting the code:
import java.util.*;
import java.io.*;
public class Project
{
public static long LIP(int q[],long p[],int degree,long despos)
{
long val=0;
for(int i=0;i<degree;++i)
{
long w=1;
for(int j=0;j<degree;++j)
if(j!=i)
w*=(despos-q[j])/(q[i]-q[j]);
val+=w*p[i];
}
return val;
}
public static void main(String[] args)
{
String S="6059"; // i used a small number in my pgm. Wat if the number
exceeds 100 digits?? How to perform the
following operations??
int k=4;
int n=8;
long x=0;
long r[]=new long[4]; //random numbers
int q[]=new int[4]; //k known shares' numbers
long p[]=new long[8]; //shares
Random R=new Random();
for(int i=0;i<k-1;i++)
{
r[i]=R.nextInt(1000);
System.out.println(r[i]); //Coefficients of the polynomial
generated randomnly
}
int b =Integer.parseInt(S);
System.out.println(b); //The secret key converted into an integer.
p[0]=(long)(b);
for(int i=0;i<n;i++)
for(int j=1;j<k-1;j++)
p[i]=p[i]+(long)(r[j]*Math.pow(i,j));
for(int i=0;i<n;i++)
System.out.println("("+i+","+p[i]+")"); // n secret shares
for(int i=0;i<k;i++)
q[i]=i;
System.out.println("The shares known are");
for(int i=0;i<k;i++)
System.out.println("("+q[i]+","+p[q[i]]+")");
x=LIP(q,p,k-1,0);
System.out.println(x);
}
}
Please help me out. One solution can be to divide the number into different parts n to use the last parts to perform the arithmetic functions as the random numbers generated are less than 1000 n the values of n are also less than 10. So their multiplication in the polynomial will be a max of 4-5 digits.