Question: PLEASE ANSWER IN PYHTON I can provide sample programs/outputs if need be Part 3a For this part you will be writing a series of functions
PLEASE ANSWER IN PYHTON
I can provide sample programs/outputs if need be
Part 3a
For this part you will be writing a series of functions that can be used as part of a "secret message encoder" program. Here are the functions you will be writing as well as some sample code that you use to test your work.
# function: add_letters # input: a word to scramble (String) and a number of letters (integer) # processing: adds a number of random letters (A-Z; a-z) after each letter # in the supplied word. for example, if word="cat" and num=1 # we could generate any of the following: # cZaQtR # cwaRts # cEaett # # if word="cat" and num=2 we could generate any of the following: # cRtaHFtui # cnnaNYtjn # czAaAitym # # output: returns the newly generated word def add_letters(word, num): # function code goes here!
Once you have written the add_letters function you should begin to work on the next function (remove_letters) which will perform the reverse operation.
# function: remove_letters # input: a word to unscramble (String) and the number of characters to remove (integer) # processing: the function starts at the first position in the supplied word and keeps it. # it then removes "num" characters from the word. the process is repeated again # if the word contains additional characters - the next character is kept # and "num" more characters are removed. For example, if word="cZaYtU" and # num=1 the function will generate the following: # # cat (keeping character 0, removing character 1, keeping character 2, removing # character 3, keeping character 4, removing character 5) # # output: returns the newly unscrambed word def remove_letters(word, num): # function code goes here!
Part 3b
Now you are going to write an "encoder / decoder" program that makes use of your three cryptographic functions. Begin by writing a program that continually asks the user to enter in an option - the user can either (e)ncode a word, (d)ecode a word or (q)uit the program.
If the user chooses to encode a word you should do the following:
Ask the user for a positive number between 1 and 5. Reprompt them if necessary.
Next, ask them to enter in a phrase that they want to encode.
Finally, apply the following algorithm to their word: Add 'num' random characters in between each letter of their word (using your add_letters) function
If the user chooses to decode a word you should do the following:
Ask the user for a positive number between 1 and 5. Reprompt them if necessary.
Next, ask them to enter in a phrase that they want to encode.
Finally, apply the following algorithm to their word:
Subtract 'num' random characters in between each letter of their word (using your remove_letters) function
Part 3c
Write a function called "shift_characters" that shifts the characters in a word up or down based on their position ASCII table. Here's the IPO notation and a sample program:
# function: shift_characters # input: a word (String) and a number of characters to shift (integer) # processing: shifts each character in the supplied word to another position in the ASCII # table. the new position is dictated by the supplied integer. for example, # if word = "apple" and num=1 the newly generated word would be: # # bqqmf # # because we added +1 to each character. if we were to call the function with # word = "bqqmf" and num=-1 the newly generated word would be: # # apple # # because we added -1 to each character, which shifted each character down by # one position on the ASCII table. # # output: returns the newly generated word def shift_characters(word, num): # function code goes here!
Include this step into the program you wrote above for Problem #3; as a result, the steps would be:
If the user chooses to encode a word you should do the following:
Ask the user for a positive number between 1 and 5. Reprompt them if necessary.
Next, ask them to enter in a phrase that they want to encode.
Finally, apply the following algorithm to their word:
Add 'num' random characters in between each letter of their word (using your add_letters) function
Shift the word 'num' characters (using your shift_characters function)
If the user chooses to decode a word you should do the following:
Ask the user for a positive number between 1 and 5. Reprompt them if necessary.
Next, ask them to enter in a phrase that they want to encode.
Finally, apply the following algorithm to their word:
Subtract 'num' random characters in between each letter of their word (using your remove_letters) function
Shift the word DOWN by 'num' characters (using your shift_characters function)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
