I want to create a collection, which can be used to find matches among the values. As you properly know, recovering the key for Double DES takes three steps. Having the plaintext and the ciphertext given:
- Encrypting the plaintext with all 2^56 possible keys and storing the results
- Decrypting the ciphertext with all 2^56 possible keys and storing the results
- Checking where the results match to retrieve the key
What I am trying to do: I am currently working with Meet-in-the-middle attack on Double DES and I have reached the point where I have to encrypt/decrypt a plaintext/ciphertext 2^56 times and store the results in order to find any matches.
Right now, I have stored the results in two HashMaps
where I store the key used and the result from the encryption/decryption. However, I am not able to figure out how I can compare the results from the two HashMaps
and then decide which keys have been used.
So, my second idea is maybe to use ListMultimap
instead where I can store the results from the encryption/decryption with the key used, but then again, I don't know how to find the matches. The matches are not necessarily on the same row.
EDIT:
I gave it a try with my two HashMaps, but I did not succeed i.e. I was not able to compare the Maps
for (int i = 0; i < Math.pow(2, 20); i++) {
for (int j = 0; j < Math.pow(2, 20); j++) {
if(hmap1.values().toArray()[i].equals(hmap2.values().toArray()[j]) )
System.out.println(hmap1.keySet().toArray()[i] + " = " + hmap2.keySet().toArray()[i] );
}
}
I forgot to mention that for the sake of testing, I am working with keys that have 20 effective bits. So, there will be 2^20 possible keys
I also forgot to mention what my HashMaps contain of. They contain of two byte arrays static Map<byte[], byte[]> hmap1 = new HashMap<byte[], byte[]>();
where the first byte array contains of the possible key and the second array contains of the result of the encryption/decryption