'''create three lists called(letters, Encoded, encryptedLettersNum)''' letters=[] Encoded=[] encryptedLettersNum=[] '''Create a String variables called(EncodedMessage) that will contain message after the encryption''' EncodedMessage='' theAlphabetSmall='a' '''create a for loop that add every element in theAlphabetSmall list to the letters list''' for i in range(0,26): letters.append(theAlphabetSmall) theAlphabetSmall=chr(ord(theAlphabetSmall)+1) '''print a question that tell the user to enter the message and save it in the message variable''' message=input ("Enter your message:\n") '''create a for loop that add every character in the message variable to the letters list and add the index+1 to the encryptionLettersNum list''' for i in range(len (message)): index=letters.index(message[i]) encryptedLettersNum.append(index+1) '''create a for loop in for loop that start from pointer +1 and end in the last character in the messag varible''' for i in range(len (message)): for j in range(i+1,len (message)): ''' create a if condation that see if the index i of the encryptedLettersNum is bigger than the index j of the encryptedLettersNum and if it is not bigger subtract them and set the index i of it to the total ''' if encryptedLettersNum[i]>encryptedLettersNum[j]: encryptedLettersNum[i]=encryptedLettersNum[i]-encryptedLettersNum[j] break '''create a for loop that take the index encryptedLettersNum then decreased by 1 then added to Encoded list''' for i in range(len (message)): Encoded.append(letters[encryptedLettersNum[i]-1]) '''create a for loop that set the encodedMassage variable to the sum of it and the index of the encoded list ''' for i in range(len (message)): EncodedMessage= EncodedMessage+Encoded[i]; '''print the message after encoded with the Encoded message''' print("The message after Encoded:\n" + EncodedMessage)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

'''create three lists called(letters, Encoded, encryptedLettersNum)'''
letters=[]
Encoded=[]
encryptedLettersNum=[]

'''Create a String variables called(EncodedMessage) that will contain message
after the encryption'''
EncodedMessage=''
theAlphabetSmall='a'

'''create a for loop that add every element in
theAlphabetSmall list to the letters list'''
for i in range(0,26):
letters.append(theAlphabetSmall)
theAlphabetSmall=chr(ord(theAlphabetSmall)+1)

'''print a question that tell the user to enter the message
and save it in the message variable'''
message=input ("Enter your message:\n")

'''create a for loop that add every character in the message variable
to the letters list and add the index+1 to the encryptionLettersNum list'''
for i in range(len (message)):
index=letters.index(message[i])
encryptedLettersNum.append(index+1)

'''create a for loop in for loop that start from pointer +1
and end in the last character in the messag varible'''
for i in range(len (message)):
for j in range(i+1,len (message)):
''' create a if condation that see if the index i of the encryptedLettersNum
is bigger than the index j of the encryptedLettersNum and if it is not bigger
subtract them and set the index i of it to the total '''
if encryptedLettersNum[i]>encryptedLettersNum[j]:
encryptedLettersNum[i]=encryptedLettersNum[i]-encryptedLettersNum[j]
break

'''create a for loop that take the index encryptedLettersNum
then decreased by 1 then added to Encoded list'''
for i in range(len (message)):
Encoded.append(letters[encryptedLettersNum[i]-1])

'''create a for loop that set the encodedMassage variable to the sum of it and
the index of the encoded list '''
for i in range(len (message)):
EncodedMessage= EncodedMessage+Encoded[i];

'''print the message after encoded with the Encoded message'''
print("The message after Encoded:\n" + EncodedMessage)

-----------------------------------------------------------------

in python 3

i want this piece of code more efficiently in one for loop

for i in range(len (message)):
for j in range(i+1,len (message)):
''' create a if condation that see if the index i of the encryptedLettersNum
is bigger than the index j of the encryptedLettersNum and if it is not bigger
subtract them and set the index i of it to the total '''
if encryptedLettersNum[i]>encryptedLettersNum[j]:
encryptedLettersNum[i]=encryptedLettersNum[i]-encryptedLettersNum[j]
break

-----------------------------------

the output must be like:

Enter your message:
abohamza
The message after Encoded:
aaggalya
Transcribed Image Text:Enter your message: abohamza The message after Encoded: aaggalya
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY