This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
JavaScript algorithmsartificial-intelligencebugbountycryptographycyber-threat-intelligencecybersecurity-projectsethical-hackinghacking-toolsmalwarenessusnetwork-monitoringnetwork-securitynmapportscannerpythonpythonprojectsthreat-intelligencevirus-scanning
Create Triple DES (Data Encryption Standards).md
Abdul Wahab Junaid8130a93d321c
diff --git a/Cryptography/Cryptography Course/Course/Triple DES (Data Encryption Standards).md b/Cryptography/Cryptography Course/Course/Triple DES (Data Encryption Standards).mdnew file mode 100644index 0000000..89d27d6--- /dev/null+++ b/Cryptography/Cryptography Course/Course/Triple DES (Data Encryption Standards).md@@ -0,0 +1,150 @@+### **Cryptography - Triple DES (3DES)**++**Triple DES (3DES)**, also known as **TDEA (Triple Data Encryption Algorithm)**, is a symmetric key block cipher that applies the **Data Encryption Standard (DES)** encryption algorithm three times to each data block to increase security. It was developed as a response to the vulnerabilities of DES, which became susceptible to brute-force attacks due to its relatively short 56-bit key length.++3DES enhances the security of DES by using either two or three different keys to perform three separate DES operations on each data block. This makes it significantly more secure than DES but also slower due to the triple encryption process.++---++### **How 3DES Works**++3DES encrypts data in three stages with either two or three different keys. The process involves applying the DES encryption algorithm to the plaintext block, then using decryption, and finally encryption again. The choice of keys and the order in which the operations are performed affect the overall security of 3DES.++There are three common variants of 3DES:++1. **3DES with Two Keys (2-key 3DES):**+ - In this configuration, the first and third encryption steps use the same key, while the second step uses a different key.+ - **Key Setup:** Two 56-bit keys (total 112-bit key length).+ - The process is as follows:+ 1. **Encrypt** the plaintext with the first key.+ 2. **Decrypt** the ciphertext with the second key.+ 3. **Encrypt** the resulting ciphertext with the first key again.+ - **Key Length:** 112 bits (56 bits for each of the two keys).++2. **3DES with Three Keys (3-key 3DES):**+ - In this variant, each of the three steps uses a different key, providing a higher level of security than the 2-key variant.+ - **Key Setup:** Three 56-bit keys (total 168-bit key length).+ - The process is as follows:+ 1. **Encrypt** the plaintext with the first key.+ 2. **Decrypt** the ciphertext with the second key.+ 3. **Encrypt** the resulting ciphertext with the third key.+ - **Key Length:** 168 bits (56 bits for each of the three keys).++3. **2-key 3DES vs 3-key 3DES:**+ - **2-key 3DES** is weaker than **3-key 3DES** because it effectively has a key length of only 112 bits, which still leaves it vulnerable to brute-force attacks with modern computational power. It is sometimes used in legacy systems but is not recommended for new applications.+ - **3-key 3DES** offers a key length of 168 bits, providing stronger security and better resistance against brute-force attacks compared to the 2-key version.++---++### **Encryption Process in 3DES**++The encryption process for **3-key 3DES** works as follows:++1. **Initial Plaintext (P):** A 64-bit plaintext block.+2. **Step 1 (First Encryption):** The plaintext is encrypted using the first key (K1) via the DES encryption algorithm.+ $\[+ C_1 = \text{DES}_{K1}(P)+ \]$+3. **Step 2 (Decryption):** The ciphertext from step 1 (C1) is decrypted using the second key (K2) via the DES decryption algorithm.+ $\[+ C_2 = \text{DES}_{K2}^{-1}(C_1)+ \]$+4. **Step 3 (Second Encryption):** The result from step 2 (C2) is encrypted using the third key (K3) via the DES encryption algorithm.+ $\[+ C_3 = \text{DES}_{K3}(C_2)+ \]$+ - The final output is **C3**, the ciphertext.++For **2-key 3DES**, the encryption process is similar, except that **K1** and **K3** are the same key, and the decryption step is done using **K2**.++---++### **Decryption Process in 3DES**++The decryption process for 3DES is the reverse of the encryption process. To decrypt the ciphertext, the same keys must be used in the reverse order.++1. **Initial Ciphertext (C3):** A 64-bit ciphertext block.+2. **Step 1 (First Decryption):** The ciphertext is decrypted using the third key (K3).+ $\[+ C_2 = \text{DES}_{K3}^{-1}(C3)+ \]$+3. **Step 2 (Second Encryption):** The result from step 1 (C2) is encrypted using the second key (K2).+ $\[+ C_1 = \text{DES}_{K2}(C2)+ \]$+4. **Step 3 (Final Decryption):** The result from step 2 (C1) is decrypted using the first key (K1).+ $\[+ P = \text{DES}_{K1}^{-1}(C1)+ \]$+ - The final result is the **plaintext (P)**.++---++### **Security of 3DES**++- **Key Length:** The strength of 3DES depends on the length of the key used. With 2 keys, it provides effective security against attacks, but with only 112 bits of security, it is vulnerable to modern brute-force attacks. In contrast, 3 keys provide 168 bits of security, which is considered to be secure against brute-force attacks.+- **Vulnerabilities:**+ - **Meet-in-the-middle attacks:** These attacks reduce the time complexity of brute-force attacks on 2-key 3DES. By precomputing possible encryption and decryption results, attackers can potentially find the correct key faster.+ - **Slower Performance:** Due to the triple encryption and decryption steps, 3DES is slower than other modern encryption algorithms like AES, especially when processing large volumes of data.++- **Deprecation:** Despite being more secure than DES, 3DES is considered to be outdated and is being phased out in favor of more modern encryption algorithms like **AES**. Many organizations are moving away from 3DES due to its performance limitations and vulnerability to certain types of attacks.++---++### **3DES Use Cases**++- **Financial Industry:** 3DES has been widely used in banking and financial systems, particularly for encrypting data in payment processing, ATMs, and point-of-sale (POS) terminals.+- **Legacy Systems:** Due to its older and more computationally expensive nature, 3DES is still used in some legacy systems that cannot be easily upgraded to newer encryption algorithms.+- **VPNs:** Some Virtual Private Network (VPN) protocols have used 3DES for securing communication channels, although more modern ciphers like AES are now preferred.++---++### **Comparison: 3DES vs AES**++| Feature | 3DES (Triple DES) | AES (Advanced Encryption Standard) |+|-------------------------|------------------------------------|------------------------------------|+| **Key Length** | 112 or 168 bits | 128, 192, or 256 bits |+| **Block Size** | 64 bits | 128 bits |+| **Speed** | Slower due to triple encryption | Faster and more efficient |+| **Security** | Secure against brute-force for 3-key version, but vulnerable to meet-in-the-middle attacks (especially 2-key) | Considered more secure against modern cryptographic attacks |+| **Standard** | Legacy standard, being phased out | Current standard in modern cryptography (NIST-approved) |+| **Usage** | Financial systems, legacy systems | Secure communications, file encryption, SSL/TLS, VPNs |++---++### **Example of 3DES Encryption (Python Implementation)**++```python+from Crypto.Cipher import DES3+from Crypto.Util.Padding import pad, unpad+from Crypto.Random import get_random_bytes++# Encryption using 3DES (with 3 keys)+key = get_random_bytes(24) # 24 bytes = 192 bits (3 DES keys of 56 bits each)+cipher = DES3.new(key, DES3.MODE_CBC) # CBC mode++data = b"Hello, this is a secret message using 3DES"+padded_data = pad(data, DES3.block_size) # Padding to match block size+ciphertext = cipher.encrypt(padded_data)++print("Encrypted:", ciphertext)++# Decryption+decipher = DES3.new(key, DES3.MODE_CBC, iv=cipher.iv)+decrypted_data = unpad(decipher.decrypt(ciphertext), DES3.block_size)++print("Decrypted:", decrypted_data.decode())+```++**Explanation of Code:**+- **Key Generation:** The key used in 3DES must be 24 bytes (192 bits). This is derived from 3 individual 56-bit keys concatenated together.+- **Padding:** Since DES operates on 64-bit blocks, padding is used to ensure the plaintext is an exact multiple of the block size.+- **Encryption and Decryption:** The ciphertext is encrypted using 3DES in **CBC (Cipher Block Chaining)** mode. The decryption process uses the same key and IV to recover the original plaintext.++---++### **Conclusion**++Triple DES was a significant improvement over the original DES and provided a more secure method for encrypting data. However, with advancements in computational power and cryptographic research, it is now considered obsolete and is being replaced by more efficient and secure algorithms like AES. Despite its declining use, 3DES has historical importance in the development of modern cryptography, particularly in securing sensitive data in legacy systems and++ financial industries.