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...

  • Please answer this python questions.Thank you! Question Two      Write a program that calculates the amount...

    Please answer this python questions.Thank you! Question Two      Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show the total pay at the end...

  • 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

  • in c++ The science of writing secret codes is called cryptography. For thousands of years cryptography...

    in c++ The science of writing secret codes is called cryptography. For thousands of years cryptography has made secret messages that only the sender and recipient could read, even if someone captured the messenger and read the coded message. A secret code system is called a cipher. In cryptography, we call the message that we want to be secret the plaintext. The plaintext could look like this:  Hello there! The keys to the house are hidden under the flower pot. Converting...

  • Write a program that counts the frequency of each letter of the alphabet as they occur...

    Write a program that counts the frequency of each letter of the alphabet as they occur in a text contained in a text file. The program should read all the characters from a file and tally the frequency for each letter of the alphabet (case-insensitive), along with white space and total character count. Your program's data structure will eventually contain the 26 numbers that will represent the frequencies of occurrence of all 26 letters of the alphabet in that file....

  • 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...

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