3DES ExampleThe DES algorithm has been around for a long time, and the 56-bit version is now easily crackable (in less than a day on fairly modest equipment). An enhancement, and one which is still fairly compatible with DES, is the 3-DES algorithm. It has three phases, and splits the key into two. Overall the key size is typically 112 bits (with a combination of the three keys - of which two of the keys are the same). [Lecture] [Tutorial] [Paper][3DES Subkeys] The process to encrypt is \(C = E_{K1}(D_{K2}(E_{K1}(P)))\) and to decrpyt \(P = D_{K1}(E_{K2}(D_{K1}(C)))\). Encrypted (Base-64) Encrypted (Hex) Decrypted |
Test Vectors
If we use ECB, we do not use the IV. The following are test vectors:
- Message= "The quick brown fox jumped over the lazy dog" and key "1234567890123456ABCDEFGH" with ECB should give "13D4D3549493D2870F93C3E0812A06DE467E1F9C0BFB16C070EDE5CABBD3CA62F217A7AE8D47F2C7198FF39162ECEC94" Ref. Note with ECB we do not use the IV. Try!
- Message= "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" and key "bill12345" with ECB should give "1122900B30BF11831122900B30BF11831122900B30BF11831122900B30BF11831122900B30BF11831122900B30BF11837591F6A1D8B4FC8A". Try!
- Message= "The quick brown fox jumped over the lazy dog" and key "1234567890123456ABCDEFGH" with CBC and IV of "12345678" should give "E6B6345F1015380284481BBCFFB9052A227FC14F73072E8D5007AC01DFEDCC2BCBCE1EB14A95ED60BA1A44700F4E18AE". Try!
- Message= "The quick brown fox jumped over the lazy dog" and key "1234567890123456ABCDEFGH" with CBC and IV of "23456789" should give "5BF29657E6064EB99E52ACC8E3A6808A761A86A7EE85C25C327022C30D939D3A8A41A9CD42689AA4481FF20155816A8C". Try!
Blog: here
Lecture
The following is a lecture on ECB and CBC:
Presentation
Why EDE?
Code Used
public void threedes(string message, string inkey) { if (message == null) return; if (inkey == null) return; try { TripleDES threedes = new TripleDESCryptoServiceProvider(); threedes.Mode = CipherMode.ECB; threedes.Key = StringToByte(inkey, 24); // convert to 24 characters - 192 bits threedes.IV = StringToByte("12345678"); byte[] key = threedes.Key; byte[] IV = threedes.IV; ICryptoTransform encryptor = threedes.CreateEncryptor(key, IV); MemoryStream msEncrypt = new MemoryStream(); CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); // Write all data to the crypto stream and flush it. csEncrypt.Write(StringToByte(message), 0, StringToByte(message).Length); csEncrypt.FlushFinalBlock(); // Get the encrypted array of bytes. byte[] encrypted1 = msEncrypt.ToArray(); encrypted = ByteToString(encrypted1); ICryptoTransform decryptor = threedes.CreateDecryptor(key, IV); // Now decrypt the previously encrypted message using the decryptor MemoryStream msDecrypt = new MemoryStream(encrypted1); CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); decrypted = ByteToString(csDecrypt); } catch (Exception ex) { encrypted = "Error:" + ex.Message.ToString(); } }