Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project Description: For this first project, you are required to create a console-based application that requests a message to be encrypted from the user via

Project Description:

For this first project, you are required to create a console-based application that requests a

message to be encrypted from the user via standard input, encrypts it and stores it in a file,

and then allows the user to decrypt the same message and presents it to the user via

standard output.

A utilities.py module will be provided to you that performs the basic file storage and retrieval.

The import statement must be used in your application to access the code in this module. So

you should put the following statement at the beginning of the code:

from utilities import store, retrieve

You must create a menu in the main() function that will provide the user several options as

shown below:

=== Simple Encryption ===

1) Encrypt

2) Decrypt

3) Exit

Enter option ==>

Initially, the user will choose Option 1, which will then cause a function named encrypt to be

executed. The encrypted function takes a cipher key and a message from the user. The

pseudocode for this function is as follows:

Encrypt:

Clear screen

Get cipher key (assume user enters integer when prompted for key request)

Check that value entered is between 0 and 127 inclusive

Convert integer cipher key to binary string and strip off "0b"

Check for 7-character length (and pad beginning with zeros if necessary)

Get message to be encrypted from standard input

Initialize encrypted message string to an empty string

Perform XOR operation on each binary bit of cipher key and message

o Get integer ascii value of each character in message

o Get binary value of ascii version of character and strip off "0b"

o Check for 7-character length (pad beginning with zeros if necessary)

o Perform XOR operation & append binary 7-bit result to encrypted string

Convert each binary bit of message character and key to an integer

Perform XOR operation on these two bits

Convert literal True and False to binary bit & append to output

Store encrypted message in file

This algorithm should be followed precisely. There is a built-in XOR operator, but this

operator cannot be used for this assignment. The purpose of the assignment is to gain

proficiency using control structures and conditional expression. The subsitution for the XOR

operation will be demonstrated during the lecture time.

The code requires clearing the screen using the os module. Clearing screen commands can

be different depending on the operating system. The following branching structure needs to

be placed in the main() function.

global clear_cmd

if os.name == "posix":

clear_cmd = "clear"

elif os.name == "nt":

clear_cmd = "cls"

else:

print "*** Unsupported System *** Application Terminating !!!"

option = "3"

The following function call can then be used in any function in your application where the

screen needs to be cleared:

# Clear screen

os.system(clear_cmd)

Once the user has encrypted the message, and it is stored in the data file, the user can then

select Option 2, which will then cause a function named decrypt to be executed. The

pseudocode for this function is as follows:

Decrypt:

Clear screen

Get cipher key (assume user enters integer when prompted for key request)

Check that value entered is between 0 and 127 inclusive

Convert cipher key to binary string and strip off "0b"

Check for 7-character length (pad beginning with zeros if necessary)

Get message to be encrypted from file

Initialize decrypted message string to an empty string

Perform XOR operation on each character of cipher key and message

o Initialize decrypted_bin_char string to an empty string

o Slice out each successive 7-bit portion of encrypted message

o Perform XOR operation and append binary result to decrypted string

Convert each binary bit of message character and key to an integer

Perform XOR operation on these two bits

Convert literal True and False to binary bit & append to output

o Append "0b" of decrypted_bin_char and get ASCII integer value

o Convert ASCII integer value to character

o Append character to decrypted message string

Clear screen

Print decrypted message to standard output

Pause screen clearing

The final option allows the user to exit from the application.

please use Python 2.7 language

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

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Discuss the five types of learner outcomes.

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago