Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Vigen re Cipher The Vigen re cipher is a method of encrypting alphabetic text using a series of interwoven Caesar ciphers, based on letters of

Vigenre Cipher
The Vigenre cipher is a method of encrypting alphabetic text using a series of interwoven Caesar ciphers, based on letters of a keyword.
Notice how in a caesar cipher, you shifted the alphabet by some integer value. Consider a mapping that maps alphabetic letters into numbers (and vice versa)
The main difference between a Vigenre cipher and the Caesar cipher, is that the Vigenre cipher changes the shift value for every character, depending on a 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 plaintext/ciphertext/keys, even if the key and plaintext/ciphertext 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 non-alphabetic characters and group the output into space-separated groups consisting of uppercase characters.
Grouping by 0 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Discuss global cultural differences in GLOBE dimensions.

Answered: 1 week ago

Question

LO1 Discuss the objectives of human resource management.

Answered: 1 week ago