Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python ver 2.7 File Encryption/Decryption Program: You are to design and write a program that allows a user to interactively select between encrypting or decrypting

Python ver 2.7

File Encryption/Decryption Program: You are to design and write a program that allows a user to interactively select between encrypting or decrypting files:

! encrypting a user-specified text-file ( .txt extension) using the encryption scheme described below to generate a new encoded file with the same name, except with a .zzz extension.

! decrypting a user-specified encrypted file (.zzz extension) using a user-specified keyword to generate a new text-file with the same name, except with a .txt extension.

The encryption scheme is a form of substitution cipher based on a user-specified positive integer key and the follow sequence of 78 characters: (Note: blank-space character between the K and l)

aA0bB1cC2dD3eE4fF5gG6hH7iI8jJ9kK lL,mM.nN?oO/pP;qQ:rR'sS"tT!uU@vV$wW%xX&yY-zZ= sequece position: 012345678901234567890123456789012345678901234567890123456789012345678901234567

01234567

The integer key is used to encrypt only the first letter in the message by shifting down the above sequence by that amount. For example, an integer key of 5 shifts B to the encrypted d. Shifting past the right end of the sequence wraps back to the beginning of the sequence. For example, shifting 5 from Z encrypts as b.

The sequence position of the first letter in the message is used as the shift amount for the second letter in the message. If the first letter was a B, then 4 is used to shift the second letter in the message since B is at position 4 (start with a at position 0, A at position 1, etc.). The sequence position of the second letter in the message is used as the shift amount for the third letter, etc. Any message character not in the above sequence (e.g., <, {) is copied to the encrypted message without modification with the previous shift amount carrying over to the next letter in the message to be encrypted. Consider the following example with key 5:

Your program also needs to: (See www.cs.uni.edu/~fienup/cs1520f17/homeworks/example_programs_hw2.zip)

! validate a correct selection whether to encrypt, decrypt, or exit.

! validate a correct positive integer for the key.

! validate that the user specified file to encrypt/decrypt exists and force the user to reenter until they specify an existing file. Feel free to make the program more user-friendly by listing all files of the appropriate type .txt or.zzz extensions.

! check if the user-specified file name for the encrypting (or decrypting) exists before opening it for writing. If it

already exists, ask the user if they are okay with it being wiped out. If they are not, ask them to pick a different file name to receive the encrypted (or decrypted) text.

Four Line Message to Encrypt with Key = 5 in file message.txt

Encrypted Message in file message.zzz

Be by the Union at 6 PM! 
 - Sam 
dF/,z83al/fHvwb& t3RRa1g 
 LJdSm 

Your program's interaction should looks something like: (Student input shown in bold.)

Welcome to the Encryption/Decryption Program Would you like to (e)ncrypt a file, (d)ecrypt a file, or e(x)it (enter e, d, or x)? encrypt

Sorry, thats an invalid choice. Please enter only e, d, or x: e What positive integer key would you like to use for encryption? five

Sorry, thats an invalid choice. Please enter a positive integer: 5

Enter the text-file name to encrypt: mesage.txt Sorry the file mesage.txt does NOT exist -- please try again! Enter the text-file name to encrypt: messaeg.txt Sorry the file messaeg.txt does NOT exist -- please try again! Enter the text-file name to encrypt: message.txt

The file message.txt was successfully encrypted using a key of 5 to the file message.zzz Would you like to (e)ncrypt a file, (d)ecrypt a file, or e(x)it (enter e, d, or x)? d What positive integer key would you like to use for decryption? 5 Enter the text-file name to decrypt: message.zzz

WARNING: The file message.txt already exists! Is it okay to wipe it out (y/n)? n Enter the file name that should be used (.txt extension will automatically be added): decryptedMessage

The file message.zzz was successfully decrypted using a key of 5 to the file decryptedMessage.txt 

Would you like (e)ncrypt a file, (d)ecrypt a file, or e(x)it (enter e, d, or x)? x Bye!

When you write your program, be sure you:

! save your program in a file called hw2.py

! make your program robust by validating the correctness of user input: verify that user-entered file names exists

(import os.path) before opening them, and check for correct menu-option, etc.

! think about the functional-decomposition (top-down) design before you start to write code! You will need to

turn in a design document (see lab 1 for an example: diagram and sentence about each function).

! dont use global variables, except for global constants with good style (ALL_CAPS_AND_UNDERSCORES).

Variables should be passed as parameters into functions and returned from functions

! use meaningful variable names with good style (i.e., useCamelCase)

! use comments (""" Multi-line Comment """) at the start of the program and immediately after each function

definition describing what they do (see lab1 diceOutcomes.py program)

! use a main function (see lab1 diceOutcomes.py program) located at the top of program with a call to it at the

bottom to start execution

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions