Question

In: Computer Science

Using the provided dictionary, develop an encryption algorithm that will convert a user-entered string into an...

Using the provided dictionary, develop an encryption algorithm that will convert a user-entered string into an encrypted string. Print the user inputted text and the corresponding encrypted text.

cipher = {"A": "T", "B": "D", "C": "L","D": "O", "E": "F","F": "A", \ "G": "G","H": "J", "I": "K", "J": "R", "K": "I","L": "C", "M": "V", \ "N": "P", "O": "W","P": "U", "Q": "X", "R": "Y", "S": "B","T": "E", \ "U": "Z", "V": "Q", "W": "S","X": "N", "Y": "M", "Z": "H"}

b) Create a corresponding decryption algorithm that utilizes the same dictionary. Print the user inputted encryption text and the corresponding decrypted text.

could I recieve help on this python problem thanks!

Solutions

Expert Solution

Part a Code for encryption:

# cipher dictionary used for encryption
cipher = {"A": "T", "B": "D", "C": "L","D": "O", "E": "F","F": "A", \
          "G": "G","H": "J", "I": "K", "J": "R", "K": "I","L": "C", "M": "V", \
          "N": "P", "O": "W","P": "U", "Q": "X", "R": "Y", "S": "B","T": "E", \
          "U": "Z", "V": "Q", "W": "S","X": "N", "Y": "M", "Z": "H"}

# function that performs encryption
def encrypt(text):
  res = ""
  #find encrypted char for each char in input and add to result
  for i in text:
    res = res + cipher[i]
  # return encrypted text
  return res

print("Enter the text to be encrypted: ",end="")
text = input()
encrypted = encrypt(text)
print("Input text is : ",text)
print("Encrypted text is : ",encrypted)

Code screenshot:

Code output:

==========================

Part B) code for decryption:

# cipher dictionary used for encryption
cipher = {"A": "T", "B": "D", "C": "L","D": "O", "E": "F","F": "A", \
          "G": "G","H": "J", "I": "K", "J": "R", "K": "I","L": "C", "M": "V", \
          "N": "P", "O": "W","P": "U", "Q": "X", "R": "Y", "S": "B","T": "E", \
          "U": "Z", "V": "Q", "W": "S","X": "N", "Y": "M", "Z": "H"}

# function to find key associated with given value in cipher
def get_key(val):
  for key, value in cipher.items():
    if(value == val):
      return key

# function that performs encryption
def decrypt(text):
  res = ""
  # for each char find the corresponding decrpyted char and add to result
  for i in text:
    res = res + get_key(i)
  return res

# take user input and perform decryption
print("Enter the text to be decrypted: ",end="")
text = input()
decrypted = decrypt(text)
print("Input text is : ",text)
print("Decrypted text is : ",decrypted)

Code Screenshot:

Code output:

====================

Proper comments and screenshots have been added to help you understand


Related Solutions

The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm....
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm. Implement these two algorithms in their own function. Now write a testing function that demonstrates your algorithms work for all interesting cases!
Instructions: Create a Java program that reads a string entered by the user and then determines...
Instructions: Create a Java program that reads a string entered by the user and then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters. Example: User enters: "This house is beautiful." a: 1 e: 2 i: 3 o: 1 u: 2 non-vowel:10
using java language "Data Structures" I have to write program which stores string entered by user...
using java language "Data Structures" I have to write program which stores string entered by user into cursor array implementation here is the code public static void main(String[] args) { CursorArray sorted =new CursorArray();//the strings must added here how can i store them                  String []inputs = new String[50];                   for (int i=0; i< 50; i++) {            System.out.println("Enter the words you want to sort and use exit to stop");...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting .Arrival time, burst time and priority values.The code should also display: (i) Gantt chart and determine the following: (ii) Determine the Turnaround time(TAT), waiting time(WT) of each process (iii) Determine the Average Waiting Time (AWT) and Average Turnaround Time (ATAT) of all processes. please write the comments
Using a technique called randomized encryption, convert textbook AES and RSA to a secured version with...
Using a technique called randomized encryption, convert textbook AES and RSA to a secured version with an initialization vector (IV). Assume we have a message (m) with 128 bits, show how to encrypt (m) with secured AES. Explain why IEEE 802.11 (i.e., WEP) is not secure due to the inappropriate usage of an IV.
Using randomized encryption, convert an AES and RSA message (m) with 128 bits into a secured...
Using randomized encryption, convert an AES and RSA message (m) with 128 bits into a secured version with an initialization vector (IV). Show how to encrypt (m) with secured AES.
c++ Develop a program that validates a password entered by a user. The password must meet...
c++ Develop a program that validates a password entered by a user. The password must meet the following criteria: Be at least six characters long. Contain at least one uppercase and at least one lowercase letter. Have at least one digit. Write a program that asks for a password and then verifies that it meets the stated criteria. If it does not, the program should display a message telling the user why and ask for another password. The program should...
PYTHON 1. Write a for loop to iterate across a user entered string in reverse order...
PYTHON 1. Write a for loop to iterate across a user entered string in reverse order Use an input statement to ask the user for a string using the prompt: Cheer? [space after the ?] and assign to a variable Start the for loop to iterate across the elements in the string in reverse order Display each element of the string on screen After the for loop ends, display the entire string 2. Write a for loop with a range...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the following information: parameters p=11,q=5, e=7 Present all the information that you will need to encrypt and decrypt only the first letter from text
Suppose an attacker obtained 128 bits of ciphertext that were encrypted using an encryption algorithm whose...
Suppose an attacker obtained 128 bits of ciphertext that were encrypted using an encryption algorithm whose keys are known to be 128 bits long. How effective is an exhaustive key search if the attacker does not know the encryption algorithm used? Provide an example of when data integrity is more important than data confidentiality? Suppose you have been asked at your new job to recommend the strength of encryption needed to protect the contents of a database. Draw up a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT