Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HOW DO YOU INITIALIZE THE CIPHERTEXT TO AN EMPTY STRING? ( PYTHON FUNCTION) I want to use substitution to create a ciphertext where EACH letter

HOW DO YOU INITIALIZE THE CIPHERTEXT TO AN EMPTY STRING? (PYTHON FUNCTION) I want to use substitution to create a ciphertext where EACH letter in the plaintext is represented by its value in the keysquare. Ignore all spaces and punctuation. For instance, the input: *?H E L L O WORLD 123!!!~ would return DGDFDXDXDDAXDDGVDXXVFVFGF

def Encrypt1(plaintext):

# dictionary is defined here. keysquare = {'Q':'AA', 'C':'AD', '3':'AF', 'T':'AG', '6':'AV', 'W':'AX', 'M':'DA', 'O':'DD', 'E':'DF', 'H':'DG', 'N':'DV', 'L':'DX', '8':'FA', 'A':'FD', '4':'FF', '2':'FG', '1':'FV', 'I':'FX', 'G':'GA', 'B':'GD', '5':'GF', 'Z':'GG', 'R':'GV', '7':'GX', 'S':'VA', 'X':'VD', '9':'VF', 'V':'VG', 'U':'VV', 'P':'VX', '0':'XA', 'K':'XD', 'J':'XF', 'F':'XG', 'D':'XV', 'Y':'XX'} # get all the keys defined in dictionary keyList = keysquare.keys() # create a list to store the encrypted string. output = list() # iterate through the input string for i in plaintext: # if each character in string is part of the keys, then # encrypt the same. if i in keyList: temp = keysquare.get(i) output.append(temp) # print the outputs. print 'INPUT: ' + plaintext print 'OUTPUT: ' + ''.join(output) Encrypt1("*?H E L L O WORLD 123!!!~#")

OUTPUT:

>python encrypt.py INPUT: *?H E L L O WORLD 123!!!~ OUTPUT: DGDFDXDXDDAXDDGVDXXVFVFGF

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

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

C7.3. Howcan a firm paya dividend withzerofree cash flow?

Answered: 1 week ago

Question

2. Do small companies need to develop a pay plan? Why or why not?

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago