# The first message in the file was decrypted, its plaintext is: plain_text = 'PICK UP THAT CAN CITIZEN' # create a list of characters of the alphabet alphabet_list = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') # use list compression to create the alphabet mapping to the integers, starting with 0 alphabet_int_list = [i for i in range(0,26)] # create a list to hold the encrypted message strings encrypted_messages_list = [] # open the file of encrypted messages in read mode, call it encrypted_messages_file with open('encrypted_messages.txt', 'r') as encrypted_messages_file: # readlines() reads all the lines of a file in one go and returns each line as a string element in a list encrypted_messages_list = encrypted_messages_file.readlines() # we use list compression to, for each line in the list, remove the whitespace (i.e. the new line character) # and then store the results in a list encrypted_messages_list = [line.strip() for line in encrypted_messages_list] print(encrypted_messages_list) Subject: Python Programming
# The first message in the file was decrypted, its plaintext is:
plain_text = 'PICK UP THAT CAN CITIZEN'
# create a list of characters of the alphabet
alphabet_list = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
# use list compression to create the alphabet mapping to the integers, starting
with 0
alphabet_int_list = [i for i in range(0,26)]
# create a list to hold the encrypted message strings
encrypted_messages_list = []
# open the file of encrypted messages in read mode, call it encrypted_messages_file
with open('encrypted_messages.txt', 'r') as encrypted_messages_file:
# readlines() reads all the lines of a file in one go and returns each line as
a string element in a list
encrypted_messages_list = encrypted_messages_file.readlines()
# we use list compression to, for each line in the list, remove the whitespace
(i.e. the new line character)
# and then store the results in a list
encrypted_messages_list = [line.strip() for line in encrypted_messages_list]
print(encrypted_messages_list)
Subject: Python Programming
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images