0% found this document useful (0 votes)
10 views

Assignment - Encrypting and Decrypting Text Files

- The document describes an assignment to write a Python program that encrypts and decrypts text files using the Magic-V cipher. - Students must submit their Python code through the e-learning portal by Tuesday, November 23rd at 11:59pm. Late submissions will not be accepted. - The program should allow users to specify encryption or decryption, a keyword, and input and output files via command line arguments. It must read from an input file, perform the encryption or decryption, and write the results to an output file.

Uploaded by

Ahmed Alsayeh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment - Encrypting and Decrypting Text Files

- The document describes an assignment to write a Python program that encrypts and decrypts text files using the Magic-V cipher. - Students must submit their Python code through the e-learning portal by Tuesday, November 23rd at 11:59pm. Late submissions will not be accepted. - The program should allow users to specify encryption or decryption, a keyword, and input and output files via command line arguments. It must read from an input file, perform the encryption or decryption, and write the results to an output file.

Uploaded by

Ahmed Alsayeh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

King Hussein Faculty of Computing Sciences

Department of Computer Science


Programming for Security Professional

Assignment: Encrypting and Decrypting Text Files


Due date: Tuesday 23/11/2021 by 11:59pm

Submitting your work


Deadline: Tuesday 23/11/2021 by 11:59pm.
All of your work must be submitted through the E-learning portal only.
You need to submit your Python code as (.py) files and it should run (no syntax errors)
Late submissions will not be accepted.

Assignment Objectives
● Use Python to develop code that encrypts and decrypts plain text
● Practice command line arguments
● Read input from a file and write output to another file

Problem Description
In order to defeat a simple letter frequency analysis1, the Magic-V cipher encodes a letter into
one of several cipher letters, depending on its position in the input document. Choose a keyword,
for example MAGIC. Then encode the first letter of the input text like this:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️
M N O P Q R S T U V W X Y Z A B C D E F G H I J K L

The encoded alphabet is just the regular alphabet shifted to start at ‘M’, the first letter of the
keyword MAGIC. The second letter is encrypted according to the following map (since we are at
letter ‘A’, the mapping of each alphabet is the same):
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

1
You can read more about frequency analysis here: https://en.wikipedia.org/wiki/Frequency_analysis
The third letter, ‘G’:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️
G H I J K L M N O P Q R S T U V W X Y Z A B C D E F

The fourth, and fifth letters in the input text are encrypted using the alphabet sequences
beginning with characters I, and C, and so on. Because the key is only five letters long, the sixth
letter of the input text is encrypted in the same way as the first (i.e., ‘M’).

For example, encrypting the string: Do not cheat!


Will yield: Po twv ohkiv!

And of course, decrypting: Po twv ohkiv!


Should yield the original string: Do not cheat!

Write a program that encrypts or decrypts a text file using this cipher and write the result
to an output file. You should allow the users of your program to supply arguments to
indicate if they are encrypting or decrypting, the cipher keyword, and to specify the input
and output files.

For example,

python3 -d WONDERFUL myInFile.txt myOutput.txt

decrypts the file myInFile.txt using the keyword WONDERFUL and writes the result to the file
myOutput.txt. (Using ‘-e’ instead of ‘-d’ indicates the user wants to encrypt the input file). It is
an error not to supply all necessary arguments.

You might also like