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

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!