knapsack.java
/** Takes a sigle block of an encrypted message, and decrypts it,
	*   by using the private sequence that is provided, to solve the
	*   Knapsack problem of finding the original bits of the message.
	*   This method retuns a int array that will contain the original
	*   message. This method does not return a byte[] becuase of sign
	*   issues.  The fact that this method returns an int array means
	*   that to write the decrypted message to a file, we cannot use
	*   the write(byte[]) method of the FileOutputStream, but we have
	*   to use the write(int b) method of the FileOutputStream.
	*   @param message the BigInteger corresponding to the encrypted block
	*   @param privateSequence The private sequence
	*   @return a byte array containing the original message
	*/
Takes a sigle block of an encrypted message, and decrypts it,
by using the private sequence that is provided, to solve the
Knapsack problem of finding the original bits of the message.
This method retuns a int array that will contain the original
message. This method does not return a byte[] becuase of sign
issues.  The fact that this method returns an int array means
that to write the decrypted message to a file, we cannot use
the write(byte[]) method of the FileOutputStream, but we have
to use the write(int b) method of the FileOutputStream.
@param message the BigInteger corresponding to the encrypted block
@param privateSequence The private sequence
@return a byte array containing the original message
Takes a sigle block of an encrypted message and decrypts it by using the private sequence that is provided to solve the Knapsack problem of finding the original bits of the message . This method retuns a int array that will contain the original message . This method does not return a byte [] becuase of sign issues . The fact that this method returns an int array means that to write the decrypted message to a file we cannot use the write ( byte [] ) method of the FileOutputStream but we have to use the write ( int b ) method of the FileOutputStream . @param message the BigInteger corresponding to the encrypted block @param privateSequence The private sequence @return a byte array containing the original message
public static int[] decrypt(BigInteger message, BigInteger[] privateSequence,
		BigInteger multiplier, BigInteger modulus) {
			message = (message.multiply(multiplier)).mod(modulus);
			int position = privateSequence.length-1;
			boolean[] bits = new boolean[8];
			int[] decrypted = new int[privateSequence.length/8];
			int count = 0;
			while (message.compareTo(BigInteger.ZERO)>0) {
				for(int i = 0; i< 8; i++) {
					if (message.compareTo(privateSequence[position])>=0) {
						bits[i] = true;
						message = message.subtract(privateSequence[position]);
						position--;
					} else {
						bits[i] = false;
						position--;
					}
				}
				int myByte = toByte(bits);
				decrypted[count++] = myByte;
			}
			return decrypted;
	}
public static int [ ] decrypt ( BigInteger message , BigInteger [ ] privateSequence , BigInteger multiplier , BigInteger modulus ) { message = ( message . multiply ( multiplier ) ) . mod ( modulus ) ; int position = privateSequence . length - 1 ; boolean [ ] bits = new boolean [ 8 ] ; int [ ] decrypted = new int [ privateSequence . length / 8 ] ; int count = 0 ; while ( message . compareTo ( BigInteger . ZERO ) > 0 ) { for ( int i = 0 ; i < 8 ; i ++ ) { if ( message . compareTo ( privateSequence [ position ] ) >= 0 ) { bits [ i ] = true ; message = message . subtract ( privateSequence [ position ] ) ; position -- ; } else { bits [ i ] = false ; position -- ; } } int myByte = toByte ( bits ) ; decrypted [ count ++ ] = myByte ; } return decrypted ; }
Takes a sigle block of an encrypted message, and decrypts it,
   by using the private sequence that is provided, to solve the
   Knapsack problem of finding the original bits of the message.
Takes a sigle block of an encrypted message and decrypts it by using the private sequence that is provided to solve the Knapsack problem of finding the original bits of the message .
//System.out.println(position);
