Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* Write a function ` vigenere _ decrypt ` using the following template. The ` method ` keyword argument allows the user to specify whether

* Write a function `vigenere_decrypt` using the following template. The `method` keyword argument allows the user to specify whether they wish to use the Kasiski method or the Index of Coincidence method to find the key length. If no method is specified, the Kasiski method is used by default.
```
def vigenere_decrypt(Y, key_start=7, key_end=12, method="kasiski"):
Y = only_letters(Y, case="upper") # Remove spaces
if method == "kasiski":
key_length_fn = key_length_kasiski
elif method == "coincidence":
key_length_fn = key_length_coincidence
else:
raise ValueError('''key_length should be either "kasiski" or "coincidence"''')
k = key_length_fn(Y, key_start=key_start, key_end=key_end) # `k` is the predicted key length
shifts =??? # The predicted shift amounts
X =??? # The predicted plaintext. Use your `vigenere` function from high above
return X.lower()
```
* Try to decrypt the above ciphertext from Section 5.2 of the textbook.
```
Y ='''zpgdl rjlaj kpylx zpyyg lrjgd lrzhz qyjzq repvm swrzy rigzh
zvreg kwivs saolt nliuw oldie aqewf iiykh bjowr hdogc qhkwa
jyagg emisr zqoqh oavlk bjofr ylvps rtgiu avmsw lzgms evwpc
dmjsv jqbrn klpcf iowhv kxjbj pmfkr qthtk ozrgq ihbmq sbivd
ardym qmpbu nivxm tzwqv gefjh ucbor vwpcd xuwft qmoow jipds
fluqm oeavl jgqea lrkti wvext vkrrg xani'''
vigenere_decrypt(Y)
```
* Select one of your classmate's Vigenre ciphertexts that were posted on Canvas Discussion and attempt to decrypt it using your `vigenere_decrypt` function. Assign the ciphertext to the variable name `Y`(use triple quotation marks to allow line breaks). Try using both key length methods.
```
vigenere_decrypt(Y, method="kasiski")
```
and
```
vigenere_decrypt(Y, method="coincidence")
```
Do they both wok?

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions