Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***Please only use for, while, if/else loop. We're not in function call yet.*** In this assignment you are asked to create a Python program to

***Please only use for, while, if/else loop. We're not in function call yet.***

In this assignment you are asked to create a Python program to perform a simple encryption of a short text message. Encryption is a security process that converts a text message that anyone can read, called plaintext, into a version that cannot be read the encrypted (or scrambled) text. The idea is to keep your message private so others cannot read it. A typical use is to encrypt a message to be sent over a network (e.g. the Internet) to another party who should be able to read it. Since messages on the Internet can be intercepted by others, encrypting it means those who do that cannot easily read what youve sent.

Your program will both encrypt and decrypt an input message. To decrypt means to convert the encrypted (scrambled) message back to its original, readable form.

The input and output of the program should:

  1. Print a start of A3 program message
  2. Repeatedly prompt the user for an input message to be encrypted and decrypted
  3. Also prompt the user for an offset integer value (explained below), one for each input message, to be used by your encryption
  4. After the user enters the message, convert it to the encrypted text and print it
  5. Then perform a decryption that converts the encrypted text back to its original form and print it
  6. Do the above for as many times as the user wants to enter messages
  7. Print an end of A3 program message

How to encrypt a message

In this assignment youll use a Caesar Cypher one of the most basic and simplest encryption methods. For each character in the message, you convert it to the encrypted version by shifting it some number of places in the alphabet. For a shift, or offset, of 1, for example, A is replaced by B, B replaced by C, etc. For an offset of 3, A is replaced by D, B replaced by E, C replaced by F, etc.

The message ABCD with an offset of 2 would become CDEF. Decryption would reverse the process by replacing each encrypted character by subtracting the offset to end up with the original message. In this example with offset = 2, C is replaced by A, D by B, E by C, and F by D. Note that the original and encrypted messages will have the same number of characters.

To simplify things, for this assignment the input message size is limited to 40 characters, and the offset size will be 10 or less. Message characters can be upper and lower case letters, numbers, and typical special characters (e.g. .,;:$%!? ).

Hints:

  1. While there are numerous ways to perform the encryption/decryption, two straight-forward ways involve (1) using the Python ord and chr functions (recommended), and (2) setting up a string of possible characters, searching for a match, and replacing using the value from the character string (more code, but it can work will be briefly explained in class).
  2. The recommended method using ord and chr:
    1. The ord function converts a character into a numeric value and the chr functions converts a numeric value back into a character. For example, ord(A) returns 65, and chr(65) returns A.
    2. In this method to encrypt, you convert each character in the input message to a number using ord, add the offset to yield a new number, then use chr to convert the result back into a character to be added to the encryption string.
    3. For an input character of A and offset of 2, the encrypted character becomes chr(ord(A) + 2), which is the character C.
    4. Decryption reverses this process by subtracting the offset from the encrypted character, so chr(ord(C) 2) turns the C back into the original A.
    5. Note that ord and chr can convert values held in a variable and dont require literal values as input
  3. Use a for loop to iterate through the original input (plaintext) message to build the encrypted message, and another for to iterate through the encrypted message to decrypt it back to the original message.
  4. Begin by making sure you understand how the ord and chr functions work by trying some examples using the Python interpreter (>>> mode). Then try a simple example by encrypting with an offset of 1 and a short message. Check for success by ensuring the decryption displays the original message. Once thats working, try larger offsets and messages.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

=+What is the most challenging part of working in social media?

Answered: 1 week ago

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago