Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Required: Add a decryption statement using python language alphabet = abcdefghijklmnopqrstuvwxyz #message = input(Enter the plaintext) #key = input(Enter the key) #two dictionaries to map

Required: Add a decryption statement using

python language

alphabet = "abcdefghijklmnopqrstuvwxyz"

#message = input("Enter the plaintext")

#key = input("Enter the key")

#two dictionaries to map index to letters and letter to index

letter_to_index = dict(zip(alphabet, range(len(alphabet))))

index_to_letter = dict(zip(range(len(alphabet)), alphabet))

# :

def encrypt(message, key):

encrypted =""

#split the message to the length of the key

split_message = [

message [i: i + len (key)] for i in range (0, len(message), len(message), len(key))

]#(start,stop,step)

#loop that start at 0 then contunue to the length of the message with jum

for each_split in split_message :

i=0

for each_letter in each_split:

#p+k mod 26

number = (letter_to_index[each_letter] + letter_to_index[key[i]]) % 26

encrypted += index_to_letter [number]

i += 1

return encrypted

def main ():

message = input("Enter the plaintext: ")

key = input("Enter the key: ")

encrypted_message = encrypt(message, key)

print("the encrypted message is: " + encrypted_message)

main()

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions