Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- Please extend the code at the bottom to do the following: - Take in a single parameter, cyphertext; the cyphertext to be worked on

- Please extend the code at the bottom to do the following:

- Take in a single parameter, cyphertext; the cyphertext to be worked on is also provided, and to be hard coded into the code.

- The code is to be a vigenere cypher.

- The extended code is to use the frequency of each letter in the English language (included below as an alphabetized vector of frequencies).

- The language to be used is Python, and is to be able to stand on its own (no external dependencies)

- The extension of the code is to do two thing: 1) return the key length (already performed by the provided code) and 2) return the key itself (the real question here)

- This question has been answered before but either did not follow parameters, or the answers we irrelevant; kindly please abide and read carefully, this is quite frustrating now. Thank you.

Extend the code at the bottom (which already finds the key length) to also find the key itself, for the given vigener cypher within the above parameters. The key length for the given text is 7, what is the key itself and the code that yields it.

ciphertext = 'GCMKGKRDBYTZLRORMTZLROGFEXIKCORSNSDZHFAZWLNCLIZIMZFWOTIPJIJOBIVQSPYURVTCSKTSNZJC' + 'RESEZMMUKZVMVCAXHFASTEXCYPAYNHIZIUUHUIMZFUAYPZQSBOAXKCSGRRMMZGRHKEXBFCGGXVJTMUXN' + 'FTOLDYYWASPITKKCCSSGRUNCDCURWDRCNZVVGWEIURJDRCORSXDSQATHVXCLOSMTYCATXMEZGCVKVPCI' + 'LTKVRIRDOXEXZFCVKVPCSPOGRUXCUAXHVQSPYIVVVHMRGRUYSQTXSPZFMFIMMDZGZGXZJBCVKVPFWLGG' + 'RUKSYSGRKZJCRECFPBECUYGGSGNRSMZSTEXCDJHFEXEEYTYTNIICCNELYCXVGLJMEQSLTUVRIRCXVPFM' + 'SPEBIITHCAILVMCDMUVRGGCVKVPXCPRATKKCJIZMTDOLEBIITGSPKVJOOPEBIITGSPXIDZZCAJIIZJCR' + 'EWRDBRATHJDBLEXMEOVCHOWKJFWOLSLMGNEIMVNZGVKHKCSPEURRHCREUJUPGRSAWGZBBEJMEVGSNHIR' + 'HHFEKEIOVGSGZVMMQMGPCNHYGKMEVJYSZGFNAGCGVVIORHORBJTRHKVZQSPSUJSGCMDYTZGZCDHCRGZR' + 'HUWVBSLEXECNOLDKQGZFMRYWFOVYTORXGCPYGRUOFGUSTYOVCYISLGRZEISDZHFESSDZBRAXCDVGREXW' + 'FAODRGGKDCLOLEUJHRHORBJTRHKIEYZCSYGIPSJTOIJQWQIZIUWMRHKMECOZIZEEOGMFURVXCPNKVFAH' + 'FIYTZSSJOTXYZGAAXGVGMBIYXZIUSIYLRWZCITLRWWRATXJJTQOSIFOVCRISIISPHUAWMSOUKRKOVCIX' + 'QZNILDKVJOOLDORXNVMWKEXZFRHKCRMSROQMCGCLEGRFOVCRNSNASPVKRKOVCIXLROFCDY';

EnglishFrequencies = [0.082, 0.015, 0.028, 0.043, 0.127, 0.022, 0.020, 0.061, 0.070, 0.002, 0.008, 0.040, 0.024, 0.067, 0.075, 0.019, 0.001, 0.060, 0.063, 0.091, 0.028, 0.010, 0.023, 0.001, 0.020, 0.001];

def getKeyLength(ciphertext):

max_shift = -1

max_coinc = -1

for shift in range(1,15):

coinc_count = 0

for i in range(len(ciphertext)):

shifted_index = (i + shift) % len(ciphertext)

if ciphertext[i] == ciphertext[shifted_index]:

coinc_count += 1

print("Shift: {0}, Coincidences: {1}".format(shift, coinc_count))

if coinc_count > max_coinc:

max_shift = shift;

max_coinc = coinc_count

return (max_shift, max_coinc)

v_shift, v_coinc_count = getKeyLength(ciphertext)

print("v_shift: {0}, v_coinc_count: {1}".format(v_shift, v_coinc_count))

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions