Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Example of a Vigen re Cipher Consider the following Plaintext: helloworld Key: key = = = = = = = = = = = =
Example of a Vigenre Cipher
Consider the following
Plaintext: helloworld
Key: key
Ciphertext: rijvsuyvjn
But how did we get from the plaintext to the ciphertext?
Since the key in our cipher is smaller than our plaintext, we will need to expand it We can do this by just repeating it which we can call a keystream.
Plaintext: helloworld
Keystream: keykeykeyk
Ciphertext: rijvsuyvjn
Now refer to the mappings from letters to numbers above if we shift h by k we get r e by e we get i and so on
Noting that characters will wrap around next character after Z is A the ciphertext character at some position
i is given by
m
o
d
c
i
p
i
k
imodk
Where
c is our ciphertext,
p is our plaintext and
k is our key.
k is the length of our key.
To obtain plaintext
p we can just reverse the shift, so
m
o
d
p
i
c
i
k
imodk
The task: Write a program that can both encrypt and decrypt text using the Vigenre cipher
Requirements
Your program will be required to both encrypt and decrypt ciphertext. The mode is specified by a program argument flag, e for encrypt mode, and d for decrypt mode.
Your program should work for both upper and lowercase plaintextciphertextkeys even if the key and plaintextciphertext do not have the same case as eachother.
Your program should also have another option for grouping output characters together. This can be specified by the g flag. What this will do is strip the ciphertext or plaintext of any nonalphabetic characters and group the output into spaceseparated groups consisting of uppercase characters.
Grouping by means the string will have no spaces. If the grouping number is larger than the amount of characters in the input, then the resulting output will also have no spaces.
The arguments can be in any order g can be either before or after the e or d flags
If both e and d flags are provided, the program should print an error.
The precedence of argument error handling follows the order of: program mode, and then grouping. That is you only print one error even if there is more than one, following that order.
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