Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please correct my mistakes in the python code. What are my mistakes and could you explain how I can program an encryption key to encrypt

image text in transcribed

image text in transcribed

Please correct my mistakes in the python code. What are my mistakes and could you explain how I can program an encryption key to encrypt the airport code to another code using ref. find? The 3-letter key must be the dog for my assignment. and the python result must be exactly same as the LAX is encrypted to OOD.

The Vigenre cipher is a generalized Caesar cipher. Each letter in a word can have a different shift, depending on the corresponding letter in a key. Suppose we want to encrypt the airport code "LAX", and the encryption key is "dog". The first letter "L" in the airport code will use the first letter of the key, "D", to get the encrypted letter. Since the index of "D" in the reference string "ABCDEF..." is 3 , we make 3 shifts from "L" to get "O", as we did with Cesar cipher in the classwork. Vigenre cipher allows us to use different shifts for each letter. The number of shifts for the next letter, "A", will depend on "O", the second letter in the key, and so forth. Write a Python program to encrypt airport codes (e.g., HKG) using the Vigenre cipher: 1) Ask the user to input a three-letter airport code and a three-letter key. 2) Encrypt the word based on the Vigenre cipher rule and display it. The program should be capable of the following. Enter a 3-letter airport code: LAX Enter a 3-letter key: dog LAX is encrypted to OOD. Follow the same submission requirement (.py file and screenshot) as before. Hint: The number of shifts is the index of the corresponding key in the reference string. If the key is "DDD", it will resemble the classwork example. Enter a 3-letter airport code: LAX Enter a 3-letter key: DDD LAX is encrypted to ODA. If the key is "AAA", you are making zero shift for every letter - not really encrypting. Enter a 3-letter airport code: LAX Enter a 3-letter key: AAA LAX is encrypted to LAX. You can recycle most scripts from the classwork. ref="ABCDEFGHIJKLMNOPQRSTUVWXYZ" key="ABCDEFGHIJKLMNOPQRSTUVWXYZ" airport=input("Enter a 3-letter airport code: "). upper() key=input("Enter a 3-letter key: "). upper() letter0 = ref [( ref.find(airport [0])%26+key.find(key[0])%26)] letter1 = ref [( ref.find(airport[1])\%26+key.find (key[1])%26)] letter2 = ref [( ref.find(airport[2])\%26+key.find (key[2])%26)] encryptedWord = letter0+letter1+letter2 print(f"\{airport\} is encrypted to \{encryptedWord\},")

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

Students also viewed these Databases questions

Question

Determine the amplitude and period of each function.

Answered: 1 week ago