ENCRYPTION Encryption: The process of converting data or information into a coded format to prevent unauthorized access. Or Converting plain text into cipher text, using key. Key features of Encryption: 1. Plaintext: The original readable data. 2. Ciphertext: The encrypted, unreadable version of the data. 3. Encryption Algorithm: A method or formula used to convert plaintext into ciphertext. 4. Key: A piece of information used in the encryption process to ensure that the ciphertext can only be decrypted by someone with the matching key. The PIGPEN cipher A simple substitution cipher that replaces letters with unique symbols derived from a grid or "pigpen" design. Example : SCHOOL S C H O O L Weakness of PIGPEN cipher 1. Easily Recognizable. (Anyone familiar with the cipher can quickly decode it without Uses of Encryption: much effort.) 1. Secure Communication: Protecting messages 2. Vulnerable to Frequency Analysis. during transmission (e.g., emails, chats). 3. The same symbols are always mapped to the 2. Data Protection: Safeguarding sensitive files same letters, making it predictable. and databases. 4. 3. Authentication: Verifying identities using The CAESER cipher encrypted credentials. A simple encryption 4. Secure Transactions: Encrypting financial technique where each transactions like online banking. letter in the plaintext is replaced by a letter that There are 2 types of encryptions: is a fixed number of 1. Symmetric Encryption positions down (or up) 2. Asymmetric Encryption the alphabet. Asymmetric Symmetric Key Two keys: a public Same key for both Benefits Drawbacks key (for encryption and • Easy to understand • Easy to Break: With encryption) and a decryption. and implement. only 25 possible private key (for keys (shifts), it's • Needs limited decryption). vulnerable to brute computing Speed Slower due to Faster because it force attacks. resources. complex uses simpler Messages can be • Frequency Analysis: mathematical algorithms. quickly translated Common letters in operations. and responded to. the ciphertext can Security More secure as Less secure if the reveal the original private keys are key is intercepted plaintext. never shared. or shared. Example HTTPS Ideal for secure communication. Best for large amount of data. Key Features of Caeser cipher: Shift / Key The number of positions each letter is shifted determines the "key" of the cipher. Example: Key →3 so A becomes D Wrapping After reaching the end of the Around: alphabet, the cipher wraps around to the beginning. e.g. X with a shift of 3 becomes A. Alphabet The cipher typically works on letters, Only: ignoring spaces, punctuation, or numbers unless otherwise specified. Caeser Encryption: Positive encryption (SHIFT FORWARD) Example: with a shift of +3, Plain text : “A”, get cipher text: A B C D E F “A” becomes “D” after encryption: Try this: Plain Text: HELLO Shift: 4 Cipher text: ………………………… Negative encryption (SHIFT BACKWARD) Example : With key of -3, Plain text : “A”, Get cipher text? A B C D E F -3 -2 -1 X Y Z A B C D E F “A” becomes “X” after encryption. For Positive Encryption: Shift the ciphertext backward by the same number. For Negative Encryption: Shift the ciphertext forward by the same number. The VIGENERE encryption The cipher uses polyalphabetic substitution. Definition: polyalphabetic substitution cipher that uses a keyword to encrypt the plaintext. Why better than Caeser cipher? It is more secure than the Caesar Cipher because it avoids the simple one-to-one substitution of letters. Vigenère cipher Encryption: Convert plaintext “BBC” into Cipher using key “CD” KEY STREAM → A B C D A A B C D B B C D E C C D E F PLAIN TEXT → +1 +2 +3 A B C D E F Caeser Decryption: D Plaintext Key Ciphertext D B C D Advantages • Polyalphabetic Nature: Makes it more resistant to frequency analysis compared to simple substitution ciphers. • Keyword-Based Encryption: Adds E F B D E G C C E Disadvantages • Keyword Repetition: Repeated keywords can expose patterns in the ciphertext. • can be broken if the keyword is short or repeated too much. • Attackers can use techniques like frequency analysis Try this: Plain text: HELLO Shift: -2 Cipher text: …………………………………. complexity and variability. on repeated sections to uncover the keyword. The RAIL FENCE cipher How the Rail Fence Cipher Works: ( DECRYPTION ) The Rail Fence Cipher is a type of transposition Know the Number of The key (number of cipher that rearranges the plaintext letters into a Rails: rails) is required. zigzag pattern on a set number of rows (rails) and Create the Rail Grid: Divide the ciphertext then reads them row by row to create the ciphertext. into the zigzag pattern with the given number How the Rail Fence Cipher Works: ( ENCRYPTION ) of rails. Choose the Number of Decide the number of Fill the Grid: Place the ciphertext in Rails: rows (rails) to use. This the grid, row by row. is the key to the cipher. Read in Zigzag: Read the grid in a zigzag Write in a Zigzag Write the message in a pattern (top to bottom, Pattern: zigzag across the rails. then back to top, and When the bottom rail is repeat) to reconstruct reached, reverse the plaintext. direction and continue until the end of the Example: Ciphertext is “HOLELWRDLO”, Key is 3. message. Read Row by Row: To create the ciphertext, read the letters from each rail row by row. Fill letters Row by Row. Example: Plain text : Coffee H O L Key: 3 E L W R D Get cipher text by rail fence. L O c e o f e f Row 1→ ce Row 2→ofe Row 3→ f Plain text is: “HELLO WORLD” Compare Caeser and Vigenère Aspect Caesar Substitution Monoalphabetic key Single fixed shift value Cipher text: ceofef Weakness of the rail fence: Method Vigenère Polyalphabetic Key word (repeated to match plain text) Shift each letter by Shift each a fixed number. letter based on corresponding keyword letter. 1. Easy to break: Even if the number of rails is unknown , it’s possible to brute force the decryption by trying all possible counts. Security Low (only 25 possible shifts) Strengths of the Rail Fence Cipher 1. Simple to Understand: Easy to implement and explain. Complexity Simple and easy to implement Structured programming ( Caeser cipher ) # Caesar Cipher Program with Subprogram for Encryption and Decryption # Step 1: Define the subprogram def caesar_cipher(text, shift, choice): #[______Assign empty string to store the encrypted & decrypted text______] result = "" #**********Loop through each character in the string 'text'*************** for char in text: #[------------------Check if the character is a letter---------------------------------------------------] if (ord(char)>=ord('A') and ord(char)<=ord('Z')) or (ord(char)>=ord('a') and ord(char)<=ord('z')): #....................Handle uppercase letters.....................: if ord(char)>=ord('A') and ord(char)<= ord('Z'): char_position = ord(char) - ord('A') if choice == "1": # Encryption new_position = (char_position + shift) % 26 elif choice == "2": # Decryption new_position = (char_position - shift) % 26 new_char = chr(new_position + ord('A')) #....................Handle lowercase letters.....................: elif ord(char)>=ord('a') and ord(char)<=ord('z'): char_position = ord(char) - ord('a') if choice == "1": # Encryption new_position = (char_position + shift) % 26 elif choice == "2": # Decryption new_position = (char_position - shift) % 26 Higher (multiple shifts based on keyword) More complex to implement and break. new_char = chr(new_position + ord('a')) result = result + new_char else: # Leave non-alphabetic characters unchanged result = result + char # .-.-.-.-.-.-. Return encrypted or deccrypted text .-.-.-.-.-.-. return result # Step 2: Main program while True: print() print("Caesar Cipher Program") print("1: Encrypt") print("2: Decrypt") choice = input("Enter 1 to Encrypt or 2 to Decrypt: ") # Validate the user's choice if choice not in ["1", "2"]: print("Invalid choice! Please enter 1 or 2.") exit() #break # Step 3: Get the text and the shift value (key) text = input("Enter the text: ") shift = int(input("Enter the shift value (key): ")) # Step 4: Call the subprogram and display the result result = caesar_cipher(text, shift, choice) print("Result:", result)