Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a python program called 'vigenere' that can take text both encode and decode a Vigenere ciphertext based on a given key word. For all

Write a python program called 'vigenere' that can take text both encode and decode a Vigenere ciphertext based on a given key word. For all given text, convert all letters to lowercase for processing. For the purposes of this assignment, assume alphabet refers to only lowercase a-z (no symbols or uppercase).

Instead of shifting each letter by the same number (like 3), we shift each letter by a regular pattern, using another word.

If we encrypt:

WE ARE DISCOVERED FLEE AT ONCE

with the keyword LEAD, we get:

W + L = ? Convert to numbers: 22 + 11 = 33 Wrap around: 33 - 26 = 7 Convert back to a letter: 7 = H

So the first letter is H. But this will take a long time to do this way! Thankfully, we have a chart we can use so we dont have to do the math!

https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher#/media/File:Vigen%C3%A8re_square_shading.svg

If you look up W on the left column and L on the top row, where they meet is the letter that is encrypted.

Of course, we can do better than the chart by writing a program to do the same thing.

You must do this program by writing particular functions that are laid out below. In your vigenere file, there should only be these six functions! You should not make any calls to input here for a user to type anything in. This file is just a library of functions. More information can be found below on how to test your program.

Functions

1. letter_to_index(letter): Given a letter, return the index position of that letter in the alphabet (assuming a is at position 0). If the letter provided is not one of the 26 letters of the alphabet, return -1.

2. index_to_letter(index): Given an integer value, return the letter at that position in the alphabet (again assuming a is at position 0). If the index provided is not between 0 and 25 (inclusive), return a question mark.

3. vigenere_encrypt(plain_letter, key_letter): Given a letter to encrypt and a key letter, return the encrypted letter. If either the plaintext letter or key letter are not in the alphabet, return the original plaintext letter.

4. vigenere_decrypt(cipher_letter, key_letter): Given a letter to decrypt and a key letter, return the decrypted letter. If either the ciphertext letter or key letter are not in the alphabet, return the original ciphertext letter.

5. encrypt(plaintext, key): Given a plaintext phrase or sentence and a key word, return the phrase or sentence encrypted. For the purposes of this assignment, you should line up the key exactly with the plaintext, including punctuation and spacing, even though the punctuation and spacing is not encrypted.

For example:

Plaintexts: This is cool!! EncryptKey: baconbaconbaco Ciphertext: uhkg js qbpl!!

Notice that we converted the uppercase letter to lowercase and ignored the punctuation and spacing.

__6. decrypt(ciphertext, key): Given a cipher text phrase or sentence and a key word, return the phrase or sentence decrypted. For the purposes of this assignment, you should line up the key exactly with the ciphertext, including punctuation and spacing, even though the punctuation and spacing is not encrypted.

For example:

Ciphertext: Uhkg Js qbpl!! DecryptKey: baconbaconbaco Plaintexts: this is cool!!

Notice that we converted the uppercase letter to lowercase and ignored the punctuation and spacing.

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

True/False Alter amounts on credit card slips.

Answered: 1 week ago