How to make a collection for the Meet-In-The-Middle attack?
up vote
1
down vote
favorite
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
java encryption collections hashmap
|
show 2 more comments
up vote
1
down vote
favorite
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
java encryption collections hashmap
You need one loop not double. One loop iterates one hashmap inside search in the second.
– kelalaka
Nov 21 at 19:57
You do not store the results of #2.
– James K Polk
Nov 21 at 19:57
Use set intersection as here
– kelalaka
Nov 21 at 20:07
@JamesKPolk: Then how am I going to find the the key for the decryption?
– Bab
Nov 21 at 20:14
Unfortunately you have left off critical details on your implementation. You say you have HashMaps but you don't say what is the HashMap lookup key and its value. Since you have DES keys and DES encryption results it matters.
– James K Polk
Nov 21 at 20:44
|
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
java encryption collections hashmap
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
java encryption collections hashmap
java encryption collections hashmap
edited Nov 21 at 20:52
asked Nov 21 at 18:54
Bab
1188
1188
You need one loop not double. One loop iterates one hashmap inside search in the second.
– kelalaka
Nov 21 at 19:57
You do not store the results of #2.
– James K Polk
Nov 21 at 19:57
Use set intersection as here
– kelalaka
Nov 21 at 20:07
@JamesKPolk: Then how am I going to find the the key for the decryption?
– Bab
Nov 21 at 20:14
Unfortunately you have left off critical details on your implementation. You say you have HashMaps but you don't say what is the HashMap lookup key and its value. Since you have DES keys and DES encryption results it matters.
– James K Polk
Nov 21 at 20:44
|
show 2 more comments
You need one loop not double. One loop iterates one hashmap inside search in the second.
– kelalaka
Nov 21 at 19:57
You do not store the results of #2.
– James K Polk
Nov 21 at 19:57
Use set intersection as here
– kelalaka
Nov 21 at 20:07
@JamesKPolk: Then how am I going to find the the key for the decryption?
– Bab
Nov 21 at 20:14
Unfortunately you have left off critical details on your implementation. You say you have HashMaps but you don't say what is the HashMap lookup key and its value. Since you have DES keys and DES encryption results it matters.
– James K Polk
Nov 21 at 20:44
You need one loop not double. One loop iterates one hashmap inside search in the second.
– kelalaka
Nov 21 at 19:57
You need one loop not double. One loop iterates one hashmap inside search in the second.
– kelalaka
Nov 21 at 19:57
You do not store the results of #2.
– James K Polk
Nov 21 at 19:57
You do not store the results of #2.
– James K Polk
Nov 21 at 19:57
Use set intersection as here
– kelalaka
Nov 21 at 20:07
Use set intersection as here
– kelalaka
Nov 21 at 20:07
@JamesKPolk: Then how am I going to find the the key for the decryption?
– Bab
Nov 21 at 20:14
@JamesKPolk: Then how am I going to find the the key for the decryption?
– Bab
Nov 21 at 20:14
Unfortunately you have left off critical details on your implementation. You say you have HashMaps but you don't say what is the HashMap lookup key and its value. Since you have DES keys and DES encryption results it matters.
– James K Polk
Nov 21 at 20:44
Unfortunately you have left off critical details on your implementation. You say you have HashMaps but you don't say what is the HashMap lookup key and its value. Since you have DES keys and DES encryption results it matters.
– James K Polk
Nov 21 at 20:44
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
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());
}
}
You can't usebyte
as the key, it doesn't implementhashCode
andequals
, so it won't work, i.e.forwardMap.contains(intermediateCipher)
will always returnfalse
– Federico Peralta Schaffner
Nov 21 at 21:26
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 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
6 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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());
}
}
You can't usebyte
as the key, it doesn't implementhashCode
andequals
, so it won't work, i.e.forwardMap.contains(intermediateCipher)
will always returnfalse
– Federico Peralta Schaffner
Nov 21 at 21:26
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 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
6 hours ago
add a comment |
up vote
1
down vote
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());
}
}
You can't usebyte
as the key, it doesn't implementhashCode
andequals
, so it won't work, i.e.forwardMap.contains(intermediateCipher)
will always returnfalse
– Federico Peralta Schaffner
Nov 21 at 21:26
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 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
6 hours ago
add a comment |
up vote
1
down vote
up vote
1
down vote
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());
}
}
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());
}
}
edited Nov 21 at 23:18
answered Nov 21 at 21:01
James K Polk
29.3k106694
29.3k106694
You can't usebyte
as the key, it doesn't implementhashCode
andequals
, so it won't work, i.e.forwardMap.contains(intermediateCipher)
will always returnfalse
– Federico Peralta Schaffner
Nov 21 at 21:26
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 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
6 hours ago
add a comment |
You can't usebyte
as the key, it doesn't implementhashCode
andequals
, so it won't work, i.e.forwardMap.contains(intermediateCipher)
will always returnfalse
– Federico Peralta Schaffner
Nov 21 at 21:26
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 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
6 hours ago
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
– Federico Peralta Schaffner
Nov 21 at 21:26
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
– Federico Peralta Schaffner
Nov 21 at 21:26
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 at 23:17
@FedericoPeraltaSchaffner: Thanks, I will change it.
– James K Polk
Nov 21 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
6 hours ago
@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
6 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418819%2fhow-to-make-a-collection-for-the-meet-in-the-middle-attack%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You need one loop not double. One loop iterates one hashmap inside search in the second.
– kelalaka
Nov 21 at 19:57
You do not store the results of #2.
– James K Polk
Nov 21 at 19:57
Use set intersection as here
– kelalaka
Nov 21 at 20:07
@JamesKPolk: Then how am I going to find the the key for the decryption?
– Bab
Nov 21 at 20:14
Unfortunately you have left off critical details on your implementation. You say you have HashMaps but you don't say what is the HashMap lookup key and its value. Since you have DES keys and DES encryption results it matters.
– James K Polk
Nov 21 at 20:44