Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++ Only) The Vigenere cipher is a type of polyalphabetic cipher. For the Caesar cipher each letter of the alphabet is substituted by a new

(C++ Only) The Vigenere cipher is a type of polyalphabetic cipher. For the Caesar cipher each letter of the alphabet is substituted by a new letter based on a constant shift value. That makes the Caesar cipher easy enough to break. For the Vigenere cipher, the shift value is variable for each letter of the input text. The shift value is calculated based on the letters from the string keyword (explained below) rather than a fixed, constant number. One letter from the keyword is chosen in a dynamic fashion based on the position of the input letter to be encrypted. Lets look at the encryption algorithm through the example below. There are two components to this type of encryption, keyword and the input text. If the keyword is TIGER and the input text we are trying to encode is BATMAN, encryption happens as follows:

image text in transcribedWe can summarize this process in three steps:

1. For each input letter find the corresponding letter from the keyword. This is done by looking at the position of the letter in the input text, then, locating the letter from the keyword at the same position. Note: if the keyword is shorter (has less characters) than the input text we need to loop back to the start, and use the letters from the keyword again. In the above example, notice that TIGER is shorter than BATMAN. TIGER has 5 characters. B is the character at position 0 in BATMAN, and N is the character at position 5, and they both follow the same encryption rules, based on the character at position 0 from TIGER, the letter T

2. Create a new alphabet sequence shifted to start from the above computed letter.

3. Find the encrypted letter for the input letter from the above created alphabet sequence.

Your function MUST be named vigenereCipher.

Your function takes three input arguments:

message - a string in all capital letters with spaces. Unencoded messages will be strings such as I LIKE CHOCOLATE or HELLO WORLD, and encoded messages will be strings such as B TOOV VPUGFEIZI or AMRPF PWXPU.

key - a string which is used to encrypt the message. It should be all capital letters. For e.g TIGER, CATS.

flag - a bool variable that controls whether your function will be encrypting or decrypting the given message. A value of true will mean your function is encrypting the given message, and a value of false will mean your function is decrypting it.

Your function should not print anything.

Your function should return the encrypted/decrypted message: a string value.

Examples:

If the input arguments are vigenereCipher(UNICORNS, TIGER, true), the function should return NVOGFKVY as the encrypted message.

If the input arguments are vigenereCipher(UNI CORNS, TIGER, true), the function should return NVO GFKVY as the encrypted message.

If the input arguments are vigenereCipher(NVOGFKVY, TIGER, false), the function should return UNICORNS as the encrypted message.

The first letter 'B' of BATMAN is encrypted using the rules: Input Letter ABCDEFGHIJKLIMNO PQRSTUVWXIYZ Encrypted Letter T U VWXYZABCDEFGH IJKLMNO PQRS The encrypted alphabet is a regular alphabet just shifted to start from T (first letter of the keyword). Therefore, the letter 'B' becomes "U' on encryption The second letter 'A' of BATMAN is encrypted using the rules: Input Letter ABCDEFGHI JKLMNOPQRST|UVWIXIYZ Encrypted LetterI J K LIMNO PQIRSTUVWXYZABCDE FIGH Again, the encrypted alphabet is a regular alphabet just shifted to start from I (second letter of the keyword). Hence, the letter 'A' becomes 'T' on encryption. The third letter 'T' of BATMAN is encrypted using the rules: Input Letter ABCDEFGHIJ KLMNOPQRSTUVWXYZ Encrypted Letter GHJKLMNOPQR STUVWXYZABCDEF The letter T becomes Z' on encryption. The fourth letter 'M' of BATMAN is encrypted using the rules: Input Letter ABC DEFGHIJ KILIMINOPQRSTUVWXYZ Encrypted LetterE FGHIJ KLMNOPQRSTUVWXYZA BCD The letter 'M' becomes 'Q' on encryption The fifth letter 'A' of BATMAN is encrypted using the rules: Input Letter ABCDEFGHI JKLMNOPQRSTUVIWXYZ Encrypted Letter RSTUVWXYZABCDEFGHIJK LMIN OPQ The letter 'A' is encrypted as 'R'. Notice that this 'A' is encrypted differently than the first 'A

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_2

Step: 3

blur-text-image_3

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago