Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to store and use large numbers containing more than 100 digits in java??

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Default How to store and use large numbers containing more than 100 digits in java??

    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)
    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++)
    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.
    for(int i=0;i<n;i++)
    for(int j=1;j<k-1;j++)
    for(int i=0;i<n;i++)
    System.out.println("("+i+","+p[i]+")"); // n secret shares
    for(int i=0;i<k;i++)
    System.out.println("The shares known are");
    for(int i=0;i<k;i++)

    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.
    Last edited by lovelysri16; February 18th, 2010 at 09:02 PM.

  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Warrington, United Kingdom
    My Mood
    Thanked 156 Times in 152 Posts

    Default Re: How to store and use large numbers containing more than 100 digits in java??

    I'm not entirely sure I understand your question but here goes.

    I assume you have a large string which is the key. You then loop through the key and generate a 3 digit number for each character.

    You then want to store this number somewhere but its ending up being long as well.

    For instance you have a 4 character key which ends up being a number of 4 x 3 = 12 numerical digits?

    So a key of 50 characters would be about 150 digits.

    Can you not store the key as a byte array then?

    // Json

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Default Re: How to store and use large numbers containing more than 100 digits in java??

    Thnx for ur quick response mate. U understood my pblm. I dunno how to use bye array, n frankly speaking i dunno whether it will solve my pblm or not. That large number which i get my converting my secret key is used in the secret shares generation.
    (k-1) times
    is the polynomial function.
    a0=Secret key in number
    (a1,...ak-1) are randomly generated numbers below 1000.
    We need to find the shares by substituting x=1,2...,n in that f(x).
    f(1),f(2),....,f(n) will be the secret shares. For their calculation, i have to substitute x=1, x=2,...,x=n in that f(x) equation. So this big number will be added to numbers which contain a max of 8 digits.
    Plzzzzzzz tell me how to make it possible? I mean how to use that byte array??

Similar Threads

  1. How can i store ArrayList objects in Access database
    By frankycool in forum JDBC & Databases
    Replies: 0
    Last Post: November 4th, 2009, 12:44 AM
  2. java.net.HttpURLConnection:large file to upload
    By tommy_725 in forum Java Networking
    Replies: 1
    Last Post: October 28th, 2009, 11:53 AM
  3. Fitting a large primitive into a small reference variable
    By Phobia in forum Java Theory & Questions
    Replies: 15
    Last Post: October 23rd, 2009, 03:10 PM
  4. exception while Read very large file > 300 MB
    By ps.ganesh in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 11th, 2009, 11:39 PM
  5. Replies: 2
    Last Post: February 4th, 2009, 12:24 PM