Question: PYTHON ENCRYPTION STYLE: Your program must contain a main function. Use whitespace and indentation properly. Limit lines to 100 characters. Give meaningful names to functions/variables,

PYTHON ENCRYPTION

STYLE:

Your program must contain a main function. Use whitespace and indentation properly. Limit lines to 100 characters. Give meaningful names to functions/variables, and follow Pythons naming standards. Localize variables. Put descriptive comments at the start of your program and each function. Since this program has longer functions, also put brief comments inside functions on complex sections of code.

ALGORITHM

Note that the below steps are just the steps for how to determine which lines to put where in the mixed file. You also need to handle all of the file reading, writing, etc. The steps of the algorithm are outlined below and you must implement these steps in python.

Import the random python library

Initialize the random library with a seed value of 123. Do this only once in your program.

However many lines there are in the input text file, repeat the following steps (line_count * 3) times

Choose two random integers starting from zero and going up to the number of lines in the file

Swap the content of the lines at these two indexes

By choosing the seed 123, you should get the same results if you follow the steps carefully.

The contents of these files must match what we expect exactly. In order to get the outputs to match, you will need to follow the same random mix

SPEC

The first program you will write should be named encrypt.py. The job of this program will be to encrypt, mix, the lines of a text file, but do it in such a way that it can be un-done later with a separate program, which you will also write).

When you run your program, your program will first request a file to to encrypt. Requesting the file name will look like:

Enter the name of a file to encrypt: X

The program will then run its encrypting algorithm on the file X. It will then save the encrypted version of the program to a file named encrypted.txt.

You might be wondering how the encryption works and how can I mix in such a way that it can be undone by another program?

Your program will mix an input file by randomly re-arranging the lines of the input file. For example, you might request that encrypt.py python file named get_credentials.py that looks like:

#get the username from a prompt username = raw_input("Login: >> ") #list of allowed users user1 = "Luke" user2 = "Leia" #control that the user belongs to the list of allowed users if username == user1: print ("Access granted") elif username == user2: print ("Welcome to the system") else: print ("Access denied")

You then run encrypt.py and request that it mix this file:

Enter the name of a file to encrypt: get_credentials.py

After encrypt.py has finished executing you encrypted.txt should look like:

elif username == user2: if username == user1: username = raw_input("Login: >> ") user2 = "Leia" print ("Access granted") print ("Welcome to the system") user1 = "Luke" #list of allowed users else: #control that the user belongs to the list of allowed users #get the username from a prompt print ("Access denied")

When encrypt.py runs, it will also write an index (key) file. This file contains the corresponding indices of each line in the encrypted file. Given the example above, index.txt should look like:

7 11 3 9 2 6 10 12 5 4 13 8 1 14

The number of each lines saves the line number that each shuffled line was in the original file. Without index.txt file, it would be very hard for any program or even a human to reassemble the program so it looks as expected. But with the index file, it isnt hard at all. Thus the file works like a secret key for the program. Whomever has access to both the index file and the encrypted text can unlock the encrypted text and other cannot.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!