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

Playing with encryption: Write a program that will read a four-digit integer entered by the user...
Playing with encryption: Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original...
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
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...
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.
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...
C++... How do I separate a C String, entered by a user, by commas? Say they...
C++... How do I separate a C String, entered by a user, by commas? Say they enter Frog,Wolf,Spider... I want a array containing the elements {Frog, Wolf, Spider} thanks Here's my idea so far... cout << "Enter the column names (c of them), each name seperated by a comma" << endl; char colNames[100]; cin >> colNames; for (int i = 0; i < 99; ++i){ if (colNames[i] == ','){ //parse the string, assign that string name to that column }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT