Question

What more powerful 1 Introduction to Iteration As you wstring the bread and better of Pythopo is that they function a s to li
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Here is the completed code for this problem. 

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please rate the answer. 

Thanks!
===========================================================================

# returns the list of letters that we want to encrypt or decrypt
def createAlphabet():
    alphabets='abcdefghijklmnopqrstuvwxyz'
    alphabets+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    alphabets+=' '
    alphabets+=',.-~#'

    return alphabets

#function takes in the plain text and the key
# function returns the encrypted text back
def encryptCeasarCipher(plaintext,key):
    alphabets = createAlphabet()

    encrypted_text=''
    for letter in plaintext:
        if letter in alphabets:
            index = alphabets.index(letter)
            forward_index = (index+key)%len(alphabets)
            encrypted_text+=alphabets[forward_index]
        else:
            encrypted_text+=letter
    return encrypted_text

# function takes in the encrypted text and the key
# function returns the decrypted text back
def decryptCeaserCipher(plaintext,key):
    alphabets = createAlphabet()
    decrypted_text=''
    for letter in plaintext:
        if letter in alphabets:
            index = alphabets.index(letter)
            backward_index = index-key%len(alphabets)
            decrypted_text+=alphabets[backward_index]
        else:
            decrypted_text+=letter
    return decrypted_text

# function ask user to enter the plain text and the key that needs to be used
# function first prints the encrypted text and again using the encrypted text and the same
# key decrypts an prints the original text again
def main():
    plaintext = input('Enter a message: ')
    key = int(input('Enter key : '))
    encrypted_message = encryptCeasarCipher(plaintext,key)
    print('Encrypted Message: ',encrypted_message)
    decrypted_message = decryptCeaserCipher(encrypted_message,key)
    print('Decrypted Message: ',decrypted_message)

main()

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

# returns the list of letters that we vant to encrypt or decrypt def createAlphabet (): alphabets=abcdefghijklmnopqrstuvwxy

for letter in plaintext: 30 if letter in alphabets: 31 alphabets.index (letter) index = 32 backward_index index-key%len (alph

Add a comment
Know the answer?
Add Answer to:
What more powerful 1 Introduction to Iteration As you wstring the bread and better of Pythopo...
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
  • C language huffman This exercise will familiarize you with linked lists, which you will need for...

    C language huffman This exercise will familiarize you with linked lists, which you will need for a subsequent programming Getting Started assignment Overview Requirements Getting Started Submit Start by getting the files. Type 264get hw13 and then cd hw13 from bash. Pre-tester You will get the following files: Q&A Updates 1. huffman.h: An empty header file, you have to define your own functions in this homework. 2. huffman.c: An empty c file, you have to define your own functions in...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean...

    Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...

  • Decrypting the APCO cipher without the key. Decryption without the key is obviously a much more...

    Decrypting the APCO cipher without the key. Decryption without the key is obviously a much more difficult process. Indeed, the purpose of encryption is to make it as difficult as possible for anyone who does not know the key to read the plain text. We will be using an unsophisticated password cracking technique called a brute force attack. A brute force attack on the APCO cipher works by trying every possible four digit key (from 0000 to 9999) and keeping...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that...

    Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that work with text files is the problem of locating a specific substring within the file. I am sure we’ve all done this many times when working with Word, Notepad, or other editors. Since we don’t have a GUI or other means of displaying the contents of a file all at once, let’s modify the problem slightly. Rather than locating a specific substring within a...

  • Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for ...

    Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...

  • cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...

    cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...

  • so i have my c++ code and ive been working on this for hours but i...

    so i have my c++ code and ive been working on this for hours but i cant get it to run im not allowed to use arrays. im not sure how to fix it thank you for the help our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses...

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