/**
   * Separates the ciphertext into containers and calculates the frequency of each byte.
   *
   * @param length The known length of the key which also defines the number of containers to create
   *     for key determination.
   * @param content The ciphertext contents read as an array of bytes.
   */
  public ByteFrequencyScanner(int length, byte[] content) {
    keyLength = length;

    // initialize each sub list
    for (int i = 0; i < length; i++) {
      ciphertext.add(new ArrayList<Byte>());
    }

    // place each byte into their respective container
    for (int i = 0; i < content.length; i++) {
      int key_pos = i % keyLength;
      ArrayList<Byte> subList = ciphertext.get(key_pos);
      subList.add(content[i]);
    }

    List<Byte> searchedBytes = new ArrayList<Byte>();
    for (ArrayList<Byte> sublist : ciphertext) {
      ByteFrequencyList count = new ByteFrequencyList();
      frequencyList.add(count);

      for (Byte b : sublist) {
        if (!searchedBytes.contains(b)) {
          searchedBytes.add(b);
          int numberOfRepetitions = countRepetition(sublist, b);
          count.add(new ByteFrequency(b, numberOfRepetitions));
        }
      }
      searchedBytes.clear();
    }
  }
 /**
  * Displays the most frequent byte in each container of monoalphabetic ciphertext. Displays more
  * than one byte in each container if a given monoalphabetic ciphertext was repeated an equal
  * number of times.
  */
 public void printFrequentBytes() {
   for (ByteFrequencyList list : frequencyList) {
     System.out.print("[");
     for (int i = 0; i < list.getRepetitiveBytes().length; i++) {
       System.out.print(String.format("%02X", list.getRepetitiveBytes()[i]));
       if (i != list.getRepetitiveBytes().length - 1) System.out.print(", ");
     }
     System.out.println("]");
   }
 }