Question
#!/usr/bin/env python # coding: utf-8 # In[ ]: # , import sys def caesar_str_enc(plaintext, K): ciphertext= for ch in plaintext: encch = caesar_ch_enc(ch, K) ciphertext
#!/usr/bin/env python # coding: utf-8
# In[ ]:
#
def caesar_str_enc(plaintext, K): ciphertext="" for ch in plaintext: encch = caesar_ch_enc(ch, K) ciphertext = ciphertext + encch return ciphertext
def caesar_ch_enc(ch, K): # everything needed to map a char to its encoded char with K as the parameter return encch
def caesar_str_dec(ciphertext, K): plaintext = "" for ch in ciphertext: decch = caesar_ch_dec(ch, K) plaintext = plaintext + decch return plain text def caesar_ch_dec (ch, K): # ... return decch
def test_module(): #K = sys.argv[1] #input_str = sys.argv[2] K =3 input_str = "this is a test" print(input_str) encstr = caesar_str_enc(input_str, K) print(encstr) decstr = caesar_str_dec(encstr, K) print(decstr) #if __name__=="__main__": # test_module()
# In this case, if you call your file like this: # >python caear_hw.py 3 "string to be encoded" # it should first print the above string # then the encrypted version of it # and next the decrypted version of it i.e., the original one
complete the program so that it can be called from command line as:
>python caesar_hw.py 2 "a test sentence"
and the output should be 2 lines:
--first line will be the encrypted version of the given sentence with k=2:
c vguv ugpvgpeg
--second line should be the decrypted version of the first line with the same K value
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started