knapsack.java
/** This method takes in the name of a file, as well as a length.
	*   This effectively splits up the message into blocks of bytes of
	*   the length provided.  This length should not be the length of the
	*   private sequence, but rather, (1/8)*(length of private sequence),
	*   since each byte will take up eight digits of the sequence.
	*   @param filename the name of the file where the message is
	*   being stored
	*   @param sequence_length the length of the blocks
	*   @return a double byte array containing the blocks of the message.
	*/
This method takes in the name of a file, as well as a length.
This effectively splits up the message into blocks of bytes of
the length provided.  This length should not be the length of the
private sequence, but rather, (1/8)*(length of private sequence),
since each byte will take up eight digits of the sequence.
@param filename the name of the file where the message is
being stored
@param sequence_length the length of the blocks
@return a double byte array containing the blocks of the message.
This method takes in the name of a file as well as a length . This effectively splits up the message into blocks of bytes of the length provided . This length should not be the length of the private sequence but rather ( 1 / 8 ) * ( length of private sequence ) since each byte will take up eight digits of the sequence . @param filename the name of the file where the message is being stored @param sequence_length the length of the blocks @return a double byte array containing the blocks of the message .
public static byte[][] split(String filename, int sequence_length) {
		ArrayList<byte[]> list  = new ArrayList<>();
		try {
			FileInputStream fs = new FileInputStream(filename);
			byte[] block = new byte[sequence_length];
			int count = 0;
			while(fs.read(block)!=-1) {
				list.add(block);
				block = new byte[sequence_length];
			}
		} catch(IOException e) {
			System.err.println(e.getMessage());
		}
		byte[][] message = new byte[list.size()][sequence_length];
		for(int i = 0; i< list.size(); i++) {
			message[i] = list.get(i);
		}
		return message;
	}
public static byte [ ] [ ] split ( String filename , int sequence_length ) { ArrayList < byte [ ] > list = new ArrayList < > ( ) ; try { FileInputStream fs = new FileInputStream ( filename ) ; byte [ ] block = new byte [ sequence_length ] ; int count = 0 ; while ( fs . read ( block ) != - 1 ) { list . add ( block ) ; block = new byte [ sequence_length ] ; } } catch ( IOException e ) { System . err . println ( e . getMessage ( ) ) ; } byte [ ] [ ] message = new byte [ list . size ( ) ] [ sequence_length ] ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { message [ i ] = list . get ( i ) ; } return message ; }
This method takes in the name of a file, as well as a length.
This method takes in the name of a file as well as a length .