1

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:

  1. Encrypting the plaintext with all 2^56 possible keys and storing the results
  2. Decrypting the ciphertext with all 2^56 possible keys and storing the results
  3. 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

Bab
  • 433
  • 5
  • 12

1 Answers1

1

Here is the basic outline:

You obtain a plaintext and ciphertext pair (P, C) which you know is the result of Double DES:

C = DESk2(DESk1(P))

Now going forward you create, say, a HashMap that maps DES intermediate output to the DES key k1 that created it. So this is important: don't get confused by the HashMap keys and the DES keys, this is just an unfortunate name overload. To avoid confusion I'll call the DES keys cryptokeys. So the HashMap is from 64-bit DES outputs to 56-bit (or 20 bit in the case of your toy) DES cryptokeys.

Java psuedo-code:

Map<Long, CryptoKey> forwardMap = new HashMap();
for (CryptoKey k1=0; k1 < (1 << 20); k1++) {
    Long intermediateCipher = DES-Encrypt(k1, P);
    forwardMap.put(intermediateCipher, k1);
}

Now to run the attack in Java psuedo-code:

for(CryptoKey k2=0; k2 < (1 << 20); k2++) {
    Long intermediateCipher = DES-Decrypt(k2, C);
    if (forwardMap.contains(intermediateCipher)) {
        k1 = forwardMap.get(intermediateCipher);
        System.out.printf("k1=%s, k2=%s work", k1.toString(), k2.toString());
    }
}
President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
  • You can't use `byte[]` as the key, it doesn't implement `hashCode` and `equals`, so it won't work, i.e. `forwardMap.contains(intermediateCipher)` will always return `false` – fps Nov 21 '18 at 21:26
  • @FedericoPeraltaSchaffner: Thanks, I will change it. – President James K. Polk Nov 21 '18 at 23:17
  • @JamesKPolk; I just want to be sure about something. What is CryptoKeys in the for loop? I read that you have named the DES keys cryptokey, but how do I use them in a for loop? – Bab Nov 24 '18 at 23:45