(Please code this in Python 3) Objectives Create a program that assists in a bas
ID: 3597445 • Letter: #
Question
(Please code this in Python 3)
Objectives
Create a program that assists in a basic form of cryptography, a substitution cypher. Write a program that will accept a phrase and convert it into code by substituting letters according to a key.
This program will also be an example of functions. You will be given a main function body. This function refers to a number of other functions which you will have to create. It's part of your job to figure out how these functions should be created and what their parameters and output should be.
The program is based on a standard text-based menu. You'll need to create methods (function) to display the menu, get input from it, and handle the details. Your program should encrypt and decrypt messages.
Here's a sample run of the basic program in action.
You may copy and paste the following code into your editor to get started. You may also type the code by hand, but your main method must be identical to the one posted here:
Please keep the following ideas in mind:
This is a substitution cypher
Each letter is replaced by another letter with no repetition
Ignore spaces and punctuation
You must account for spaces (I ignored them, but there are other legitimate responses.)
The best program will also account for punctuation and other symbols. (Ignoring them is fine.)
Manage Capitalization
In most cryptographic applications, all letters are converted to uppercase. Please follow this convention or deal with potential case conversion problems in another way.
Use Functions
You may not make significant changes to the main function. Determine which functions are necessary and create them. (The blackbelt project does allow for one slight modification, noted below.) Do not turn in a program with only a main() function!! Write the code necessary for Python to run the main function as expected
Pass data between functions
Your functions may require some input and return some output. Part of the task is to determine how the methods are to be created.
Using a key
There's several workable answers, but I used a string with all the alphabet characters and a second string with a "scrambled" version of the alphabet.
Useful String methods
This program is all about string manipulation, so you may want to use help("str") in your python shell to look up some useful techniques. Here are a few things you might need to know how to do:
determine the length of a string
convert a string to upper case
find the position of a character in a string
Determine the character at a certain position in a string
Explanation / Answer
""" crypto.py Implements a simple substitution cypher """ alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "XPMGTDHLYONZBWEARKJUFSCIQV" def main(): keepGoing = True while keepGoing: response = menu() if response == "1": plain = input("text to be encoded: ") print(encode(plain)) elif response == "2": coded = input("code to be decyphered: ") print (decode(coded)) elif response == "0": print ("Thanks for doing secret spy stuff with me.") keepGoing = False else: print ("I don't know what you want to do...")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.