Question: import string all_letters = string.ascii_letters dict1 = {} plain_txt = input(Enter plain text : ) key = int(input(Enter key : )) for i in range(len(all_letters)):
import string all_letters = string.ascii_letters dict1 = {} plain_txt = input("Enter plain text : ") key = int(input("Enter key : ")) for i in range(len(all_letters)): dict1[all_letters[i]] = all_letters[(i + key) % len(all_letters)] cipher_txt = [] for char in plain_txt: if char in all_letters: temp = dict1[char] cipher_txt.append(temp) else: temp = char cipher_txt.append(temp) cipher_txt = "".join(cipher_txt) print("Cipher Text is: ", cipher_txt) dict2 = {} for i in range(len(all_letters)): dict2[all_letters[i]] = all_letters[(i - key) % (len(all_letters))] decrypt_txt = [] for char in cipher_txt: if char in all_letters: temp = dict2[char] decrypt_txt.append(temp) else: temp = char decrypt_txt.append(temp) decrypt_txt = "".join(decrypt_txt) print("Recovered plain text :", decrypt_txt)
Question 1 solved. Please solve question 2 for me.
Problem 1. Write computer programs for the Substitution Cipher based on Z2, which is cor- responding to 26 alphabetic characters 0 - 25), space (26), and ", " (27) "" (28). The key is a random permutation on Zg. Write down encryption and decryption programs. For the encryption, the plaintext and the key need to be input. The out put will be the ciphertext. Select a paragraph of text (I don't think any two people will choose a same paragraph if they choose independently) and encrypt it using your encryption algorithm. Then use your decryption program to check the correctness. You can use Java, C or other computer languages. Record your plaintext, ciphertext and the key in your answer sheet. Problem 2. Write computer programs for the Permutation Cipher based on Z, as in Problem 1. In encryption program, the inputs are a value of m (the size of permutation), a permutation as the key and the plaintext, and the output is the ciphertext. Write the decryption program accordingly. Try your programs by some text. Note that since 1 m and the length of plaintext is not fixed, paddings might be added to the end of plaintext by the program. You may think about what kind padding is better for the security and design your paddings. Problem 1. Write computer programs for the Substitution Cipher based on Z2, which is cor- responding to 26 alphabetic characters 0 - 25), space (26), and ", " (27) "" (28). The key is a random permutation on Zg. Write down encryption and decryption programs. For the encryption, the plaintext and the key need to be input. The out put will be the ciphertext. Select a paragraph of text (I don't think any two people will choose a same paragraph if they choose independently) and encrypt it using your encryption algorithm. Then use your decryption program to check the correctness. You can use Java, C or other computer languages. Record your plaintext, ciphertext and the key in your answer sheet. Problem 2. Write computer programs for the Permutation Cipher based on Z, as in Problem 1. In encryption program, the inputs are a value of m (the size of permutation), a permutation as the key and the plaintext, and the output is the ciphertext. Write the decryption program accordingly. Try your programs by some text. Note that since 1 m and the length of plaintext is not fixed, paddings might be added to the end of plaintext by the program. You may think about what kind padding is better for the security and design your paddings
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
