Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started