0% found this document useful (0 votes)
93 views3 pages

COSC1100 Assignment3 SecretCodes-Substitution

This document provides requirements for an assignment to create a Python program that encodes and decodes text using a substitution cipher. The program must prompt the user to encode or decode text, call the appropriate function, and print the result. The encode and decode functions will implement a substitution cipher that replaces English letters with those from the Al Bhed alphabet according to a provided cipher table, running the cipher multiple times equal to the key value. Guidance including pseudocode is provided for the encode function.
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)
93 views3 pages

COSC1100 Assignment3 SecretCodes-Substitution

This document provides requirements for an assignment to create a Python program that encodes and decodes text using a substitution cipher. The program must prompt the user to encode or decode text, call the appropriate function, and print the result. The encode and decode functions will implement a substitution cipher that replaces English letters with those from the Al Bhed alphabet according to a provided cipher table, running the cipher multiple times equal to the key value. Guidance including pseudocode is provided for the encode function.
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/ 3

Assignment 3: Secret Codes (Arrays & Functions)

Assignment for COSC 1100 – Intro to Programming

Prior to attempting this problem, you should have done the following:
1. View the Content, including assigned readings for weeks 5 through 9.
2. Viewed the Functions in Python video from week 9 and completed the associated Pre-Class Activity.

General Requirements
1. This assignment is to be completed individually. Group submissions will not be considered.
2. Analyze the problem, design a documented plan (i.e. flowchart or pseudo-code), code and test a solution
following the step-by-step approach presented in this course.
3. Submit your solution and plan to the appropriate assignment folder on DC Connect by the due date
provided.
4. Your instructor will assign a grade and post feedback on your submission to DC Connect.

Program Requirements
Create a simple Python application following the requirements below to allow a user to encode a piece of text
using a cipher, or to decode the text using the same cipher. A “cipher” is a method of making a coded message
that can be “deciphered” – usually the input to a cipher is the message to encode and some kind of “key” value
that makes it make sense.

In your program, after the user picks whether they are encoding or decoding the text, the user will enter text
and it will either be encoded or decoded. Since your program allows both encoding and decoding, you will be
able to (partly) test if the cypher works using just your own program.

Detailed Requirements:
• Initial prompt: When the program starts the user is prompted to enter “1” to encode, “2” to decode, or
“3” to exit.
• If the user inputs “1”:
o Accept one text input from the user; validation of this input may not be necessary
o Pass the user’s text input to an “encode” function
o Print the encoded text string that was returned by the “encode” function
o Do the initial prompt again
• If the user inputs “2”:
o Accept one text input from the user; validation of this input may not be necessary
o Pass the user’s text input to an “decode” function
o Print the decoded text string that was returned by the “decode” function
o Do the initial prompt again
• If the user inputs “3”:
o End the program
• If the user inputs anything other than “1”, “2” or “3”, re-prompt them with the initial prompt again.

Page 1 of 3
Assignment 3: Secret Codes (Arrays & Functions)
Assignment for COSC 1100 – Intro to Programming
Requirements for the Cipher Functions:
In this case, we will be using a Substitution cipher, which is a very simple type of cipher that operates by
replacing characters from one “alphabet” with the letters of another “alphabet”. In our case, we will convert
from English letters into the Al Bhed language from Final Fantasy X. Your encode and decode functions will each
have two parameters: the message, and a key value, where the key value represents how many times the
substitution cipher will run. The key will have a default value of 1.

English Al Bhed English Al Bhed English Al Bhed


A Y J Z S C
B P K G T D
C L L M U I
D T M S V J
E A N H W F
F V O U X Q
G K P B Y O
H R Q X Z W
I E R N
There are many viable ways to implement a Substitution cipher in Python, but probably the easiest way for our
needs would be to declare two strings that include each of the two entire alphabets. The English alphabet could
be “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz” and the Al Bhed alphabet would be similar
but re-arranged based on the substitution table above. Then, given a coded message, for each letter, match that
letter’s position in the first alphabet with the same position in the second alphabet.

Here is some partial pseudocode for the encode function that you can make use of:

Start with an empty string called encrypted_string


For each letter_index, counting up from 0 to the length of the input
Assume that there is no match found (match_found = False)

For each alphabet_indx in the alphabet


If the letter at letter_index matches the letter at alphabet_index
Add that letter to the encrypted_string
Set match_found to True
If after going through the whole alphabet, match_found is False
Add the original letter at letter_index to the encrypted string

Notably omitted from this code snippet is the key value. The entire substitution algorithm should run a number
of times equal to the key (which has a default value of 1). Each additional time it is encoded will “scramble” it
differently, and decoding it the same number of times will unscramble it.

Style Guide:
To be eligible for full marks on this or any assignment in this course your application must conform to the
requirements as outlined above as well as our prescribed style guide, in this case making sure to observe the
PEP8 naming conventions for Python as well as appropriate and complete program documentation.

Page 2 of 3
Assignment 3: Secret Codes (Arrays & Functions)
Assignment for COSC 1100 – Intro to Programming
Development Hints:
• As always, start with your planning steps. The pseudocode shown above may be part of the process and plan
(steps 3 and 4 of 10).
• Only after planning, consider how you can “translate” the given pseudocode into Python code.
• Ciphers are a very common programming exercise and thus there are numerous reference materials and
possibly even full solutions available on the web. However, be cautious with these!
o Make sure any “borrowed” code works and that your program actually meets our requirements.
o Make sure all code in your program conforms to our PEP8 style guide.
o Reference any code directly taken from an online resource or another person, or this will be
considered an incident of plagiarism. You can just do this in a comment before the part you have
taken from another source.

Sample Output:

Page 3 of 3

You might also like