knapsack.java
/** This method returns a superincreasing sequence with a given length, where
	*   the first number has at most a given number of bits.  This method first
	*   checks to ensure that the length of the sequence is a multiple of 8, so
	*   that it works with the encrypt method.
	*   @param length The number of terms to be in the sequence
	*   @param start_length The maximum number of bits for the first number in the
	*   sequence
	*   @return The superincreasing sequence
	*/
This method returns a superincreasing sequence with a given length, where
the first number has at most a given number of bits.  This method first
checks to ensure that the length of the sequence is a multiple of 8, so
that it works with the encrypt method.
@param length The number of terms to be in the sequence
@param start_length The maximum number of bits for the first number in the
sequence
@return The superincreasing sequence
This method returns a superincreasing sequence with a given length where the first number has at most a given number of bits . This method first checks to ensure that the length of the sequence is a multiple of 8 so that it works with the encrypt method . @param length The number of terms to be in the sequence @param start_length The maximum number of bits for the first number in the sequence @return The superincreasing sequence
public static BigInteger[] privateSequence(int length, int start_length) {
		if (length%8 != 0) {
			length += (8-length%8);
		}
		BigInteger[] sequence = new BigInteger[length];
		Random r = new Random();
		BigInteger start = new BigInteger(start_length,r);
		sequence[0] = start;
		BigInteger sum = start;
		for(int i = 1; i< length; i++) {
			BigInteger next = sum;
			BigInteger multiplier = new BigInteger(Integer.toString(r.nextInt(100000+i)));
			multiplier = multiplier.add(new BigInteger(Integer.toString(r.nextInt(10000000))));
			next = next.multiply(multiplier);
			sum = sum.add(next);
			sequence[i] = next;
		}
		return sequence;
	}
public static BigInteger [ ] privateSequence ( int length , int start_length ) { if ( length % 8 != 0 ) { length += ( 8 - length % 8 ) ; } BigInteger [ ] sequence = new BigInteger [ length ] ; Random r = new Random ( ) ; BigInteger start = new BigInteger ( start_length , r ) ; sequence [ 0 ] = start ; BigInteger sum = start ; for ( int i = 1 ; i < length ; i ++ ) { BigInteger next = sum ; BigInteger multiplier = new BigInteger ( Integer . toString ( r . nextInt ( 100000 + i ) ) ) ; multiplier = multiplier . add ( new BigInteger ( Integer . toString ( r . nextInt ( 10000000 ) ) ) ) ; next = next . multiply ( multiplier ) ; sum = sum . add ( next ) ; sequence [ i ] = next ; } return sequence ; }
This method returns a superincreasing sequence with a given length, where
   the first number has at most a given number of bits.
This method returns a superincreasing sequence with a given length where the first number has at most a given number of bits .