Question: * 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!