/** * 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(); } }