Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you will attempt to crack a Vigenere cipher using a dictionary attack. Ordinary words can make convenient keys because they are easy to remember, but

you will attempt to crack a Vigenere cipher using a dictionary attack.
Ordinary words can make convenient keys because they are easy to remember, but this practice is far
from secure. For this task, you are given a cipher and a list of some of the most common words in the
English language. One of those words was used as the key to encrypt the cipher, and your job is to write
the code to figure out which one it is. For simplicity, you can assume that all words in the original
message are also chosen from the provided list of dictionary words.

Starter Code:

DICTIONARY = [] ## This is a premade variable with designated words for the task.

def vigenere_dictionary_attack(c: str) -> str:
# TODO: Write the necessary code to get the MESSAGE (m) from the cipher (c).
m = ‘’
return m

This code does not work:

def vigenere_dictionary_attack(c: str) -> str:

c = ''.join(filter(str.isalpha, c)).upper()

for keyword in DICTIONARY:

keyword = keyword.upper()

# repeat the keyword to match the length of the cipher

repeated_keyword = (keyword * (len(c) // len(keyword) + 1))[:len(c)]

# decrypt the cipher using the repeated keyword

m = vigenere_decrypt_cipher(c, repeated_keyword)

return m

Code to Test against:

import unittest

from task import vigenere_dictionary_attack

class TestVigenereDictionaryAttack(unittest.TestCase):

def test_1(self):
m_expected = 'PHOTOGRAPHYSEPARATELYPROTECTEDLITIGATIONTREATMENTCONSIDERINGANNOUNCEMENTIDENTICALLIABILITIESINSPECTOR'

m = vigenere_dictionary_attack('XKSGHOWITYGVICTZFBICGSVBMMHBIUTLXVZIYQSEBUINMUJVXTWQWVWMWQRXIQRBNVHMQVVWMQXVYQGRTOMNUQQQXZMVMALXJKXFZ')
self.assertEqual(m, m_expected)


if __name__ == '__main__':
unittest.main()

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Analyzing and Improving the Vigenre Cipher Attack Understanding the Code The provided code attempts a dictionary attack on a Vigenre cipher It iterate... 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

Financial and Managerial Accounting

Authors: Jonathan E. Duchac, James M. Reeve, Carl S. Warren

11th Edition

9780538480901, 9781111525774, 538480890, 538480904, 1111525773, 978-0538480895

More Books

Students also viewed these Accounting questions