Question

In Python, write a program that assigns “codes” to each letter of the alphabet. For example,...

In Python, write a program that assigns “codes” to each letter of the alphabet. For example,

codes = {“a”: “%”, “b”:”9”, “c”:”?”,….}

Write a function that takes in this dictionary and a sentence to encrypt the sentence. Write another function that takes the encrypted sentence and decrypt it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#method to encrypt a sentence given codes 2 def encrypt (codes,sentence): #loop through sentence for l in sentence: 4 #get th

#method to encrypt a sentence given codes

def encrypt(codes,sentence):

enc = ""

#loop through sentence

for l in sentence:

#get the value from charcter l

enc += codes[l]

return enc

#method to decrypt a sentence given codes

def decrypt(codes,sentence):

dec = ""

#loop through sentence

for l in sentence:

#get the key

key = [key for (key, value) in codes.items() if value == l][0]

dec += key

return dec

codes = {"a":"%","b":"9","c":"?"}

encrypted = encrypt(codes,"abc")

print("Encrypted Sentence:",encrypted)

decrypted = decrypt(codes,encrypted)

print("Decrypted Sentence:",decrypted)

"""

sample output

Encrypted Sentence: %9?

Decrypted Sentence: abc

"""

Add a comment
Know the answer?
Add Answer to:
In Python, write a program that assigns “codes” to each letter of the alphabet. For example,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...

    File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to successfully complete chapter 9 programming exercise #3. File Encryption and Decryption Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example: codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .} Using this example, the letter A would be assigned the symbol %, the letter a would...

  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','b' :'#,, etc ) Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol e, and so forth. The program should open a...

  • Security is an important feature of information systems. Often, text is encrypted before being sent, and...

    Security is an important feature of information systems. Often, text is encrypted before being sent, and then decrypted upon receipt. We want to build a class (or several classes) encapsulating the concept of encryption. You will need to test that class with a client program where the main method is located. For this project, encrypting consists of translating each character into another character. For instance, if we consider the English alphabet, including characters a through z, each character is randomly...

  • 2. The following statement was encrypted by shifting each letter in the alphabet by 3. Spaces...

    2. The following statement was encrypted by shifting each letter in the alphabet by 3. Spaces between words were not encrypted. Decrypt the message, PHH WPH DWW KHX VXD OSO DFH DWH LJK WRF ORF N 3. The following statement was enor

  • Write a python program that does the following: takes as input from the user an English...

    Write a python program that does the following: takes as input from the user an English sentence calls the function vc_counter() that: takes a string argument counts the number of vowels and consonants in the string returns a dictionary of the counts, using the keys total_vowels and total_consonants Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions. Example: Enter an English sentence: The quick brown fox's jump landed past the lazy dog! Total #...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • Write a program in python or c++ that has two functions: Function one is called: _encrypt...

    Write a program in python or c++ that has two functions: Function one is called: _encrypt Function Two is called: _decrypt Function one takes plain text ,and assesses the indexed value of each letter in the string. For example, a=1,b=2 . It then adds three to the indexed valus , and produces encrypted text , based off of the plain text. Function two reverse this. here is sample output: _encrypt(‘how do you do’) Unsecured: howdoyoudo Secured: lsahscsyhs _decrypt(‘lsahscsyhs’) Unsecured: lsahscsyhs...

  • Write a program in python that asks the user to input a sentence. The program will...

    Write a program in python that asks the user to input a sentence. The program will ask the user what two letters are to be counted. You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence. You are not allowed to use python built-in function "count()" or you'll get a Zero! Output will show the sentence, the letter, and the number of times the letter appears in...

  • Python: Write a program that lets the user enter a string and displays the letter that...

    Python: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string, ignore spaces, punctuation, and Upper vs Lower case. Create a list to hold letters based on the length of the user input Convert all letters to the same case Use a loop to check for each letter in the alphabet Have a variable to hold the largest number of times a letter appears, and replace the value when...

  • THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM...

    THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM FOR PYTHON This time, we will write a program that uses functions to parse through all those names in a List object (see below for the "us_counties" list) to count the number of occurrences each vowel (a, e, i, o, u) has in all the names. We want 5 separate answers, one for each vowel. Not looking for output here. All my solution will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT