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 Simple Substitution Cipher.md
Abdul Wahab Junaidefe662f91193
diff --git a/Cryptography/Cryptography Course/Course/Simple Substitution Cipher.md b/Cryptography/Cryptography Course/Course/Simple Substitution Cipher.mdnew file mode 100644index 0000000..a462ddc--- /dev/null+++ b/Cryptography/Cryptography Course/Course/Simple Substitution Cipher.md@@ -0,0 +1,113 @@+### **Cryptography - Simple Substitution Cipher**++The **Simple Substitution Cipher** is one of the most basic encryption techniques in cryptography, where each letter of the plaintext is replaced by another letter or symbol. The key in a substitution cipher is a permutation of the alphabet. This means each letter of the plaintext is substituted by a corresponding letter from a scrambled alphabet, which serves as the key. The key must be kept secret to maintain the cipher's security.++### **How Simple Substitution Cipher Works**++1. **Plaintext**: This is the original message you want to encrypt.+2. **Alphabet**: A fixed alphabet (e.g., A to Z) is used to map each letter of the plaintext.+3. **Key**: The key is a scrambled version of the alphabet. Each letter of the plaintext is replaced by the corresponding letter from the key.++For example, if we use the following key:++| Plaintext | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |+|-----------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|+| Ciphertext| Q | W | E | R | T | Y | U | I | O | P | A | S | D | F | G | H | J | K | L | Z | X | C | V | B | N | M |++If the plaintext is "HELLO", using the above substitution key, we would substitute each letter of "HELLO" with the corresponding letter from the key:++- H → I+- E → T+- L → S+- L → S+- O → L++Thus, the ciphertext would be **"ITSSL"**.++### **Decryption**++To decrypt the message, the receiver must know the key (the scrambled alphabet) and reverse the substitution process. This means they replace each letter in the ciphertext with the letter from the plaintext alphabet that corresponds to the letter in the ciphertext alphabet.++For the ciphertext **"ITSSL"**, using the same key:++- I → H+- T → E+- S → L+- S → L+- L → O++Thus, the plaintext is **"HELLO"**.++### **Python Code for Simple Substitution Cipher**++Here’s a Python implementation of both encryption and decryption for a simple substitution cipher:++```python+# Function to encrypt the plaintext using a substitution cipher+def encrypt_substitution(plaintext, key):+ alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+ plaintext = plaintext.upper()+ ciphertext = ''++ for char in plaintext:+ if char in alphabet: # Encrypt only alphabetic characters+ index = alphabet.index(char)+ ciphertext += key[index]+ else:+ ciphertext += char # Non-alphabet characters remain unchanged+ return ciphertext++# Function to decrypt the ciphertext using a substitution cipher+def decrypt_substitution(ciphertext, key):+ alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+ ciphertext = ciphertext.upper()+ plaintext = ''++ for char in ciphertext:+ if char in key: # Decrypt only alphabetic characters+ index = key.index(char)+ plaintext += alphabet[index]+ else:+ plaintext += char # Non-alphabet characters remain unchanged+ return plaintext++# Example of encryption and decryption+key = 'QWERTYUIOPASDFGHJKLZXCVBNM' # The scrambled alphabet used as the key++plaintext = "HELLO"+ciphertext = encrypt_substitution(plaintext, key)+print(f"Ciphertext: {ciphertext}")++decrypted_text = decrypt_substitution(ciphertext, key)+print(f"Decrypted Text: {decrypted_text}")+```++### **Explanation of the Code:**++1. **`encrypt_substitution` function**: This function takes the plaintext and the key as input. It loops over each character in the plaintext, and if it's a letter, it finds its corresponding letter from the key and appends it to the ciphertext.++2. **`decrypt_substitution` function**: This function takes the ciphertext and the key as input. It reverses the process by finding each character in the ciphertext's key and replacing it with the corresponding letter from the alphabet to get the original plaintext.++### **Example Output:**++```+Ciphertext: ITSSL+Decrypted Text: HELLO+```++### **Advantages of Simple Substitution Cipher:**++1. **Simple to Implement**: The substitution cipher is easy to understand and implement.+2. **Fast Encryption/Decryption**: It allows fast encryption and decryption since it's a direct substitution.+3. **Good for Educational Purposes**: It's a useful cipher for learning about basic encryption concepts.++### **Drawbacks of Simple Substitution Cipher:**++1. **Vulnerable to Frequency Analysis**: The simple substitution cipher is vulnerable to frequency analysis, where attackers can look at the frequency of letters in the ciphertext and compare them to the known frequencies of letters in the language.+ - For example, in the English language, 'E' is the most frequent letter, so by analyzing the frequency of letters in the ciphertext, an attacker can guess the most likely mapping.+2. **Small Key Space**: The key space for a substitution cipher is relatively small because it's simply a permutation of the 26 letters of the alphabet, leading to a limited number of possible keys (26! = 403291461126605635584000000).+3. **Pattern Preservation**: The pattern of the plaintext is preserved in the ciphertext. For example, repeating letters in the plaintext will appear as repeating letters in the ciphertext, which can be exploited by an attacker.++### **Conclusion**++The **Simple Substitution Cipher** is an elementary encryption method that is easy to understand and implement, but it is not secure by modern standards due to its vulnerability to frequency analysis. While it is not suitable for securing sensitive information, it is still valuable for demonstrating the basic concepts of encryption and the importance of randomness and key complexity in cryptography.