Complete the function encrypt, which takes an unencrypted, plaintext message called plaintext and encrypts it according to the following algorithm. The function then returns the encrypted ciphertext message. 1. Using a for-loop, swap the character at each even-indexed position with the one to its right. (Examples: abcdefg becomes badcfe; abcdefg becomes badcfeg) You'll have to carefully accomodate for even-lengthed and odd-lengthed strings. 2. Then, using another for-loop, replace every uppercase letter with its lowercase equivalent, and replace every lowercase letter with its uppercase equivalent. 3. (May be combined with the loop in the previous step in the code.) Except for the character o, replace each digit character with 10 minus that digit. (Examples: 2 becomes 8, 9 becomes 1.) Hint: use ord and/or chr and/or str and/or int instead of a 10-way if- statement! Examples: Function Call encrypt('abCDefGHIJKLMnopQ') encrypt('ABCdefGHIjkL') encrypt('0123456789') encrypt('123456789') encrypt('Stony Brook University 2022') encrypt ("What's a Seawolf? I'm a Seawolf! Fan level 9000!") encrypt('1234 Python programming 4321!') [ ] 1 import string Return Value BAdcFEhgJilkNmPOq baDcFEhgJilk 9078563412 896745231 TSNO YRbO0 KNUVIREISYT8 808 HWTAS AS AEOWFL ?'i M AESWALO!Ff NAL VELE1 0010 8967p TYOH NRPGOARMMNI G7698!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Complete the function encrypt, which takes an unencrypted, plaintext message called plaintext and encrypts it according to the following
algorithm. The function then returns the encrypted ciphertext message.
1. Using a for-loop, swap the character at each even-indexed position with the one to its right. (Examples: abcdefg becomes badcfe;
abcdefg becomes badcfeg) You'll have to carefully accomodate for even-lengthed and odd-lengthed strings.
2. Then, using another for-loop, replace every uppercase letter with its lowercase equivalent, and replace every lowercase letter with its
uppercase equivalent.
3. (May be combined with the loop in the previous step in the code.) Except for the character o, replace each digit character with 10 minus
that digit. (Examples: 2 becomes 8, 9 becomes 1.) Hint: use ord and/or chr and/or str and/or int instead of a 10-way if-
statement!
Examples:
Function Call
encrypt('abCDefGHIJKLMnopQ')
encrypt('ABCdefGHIjkL')
encrypt('0123456789')
encrypt('123456789')
encrypt('Stony Brook University 2022')
encrypt ("What's a Seawolf? I'm a Seawolf! Fan level 9000!")
encrypt('1234 Python programming 4321!')
[ ]
1 import string
2
3 def encrypt (pla text):
4
5
Return Value
BAdcFEhgJilkNmPOq
6
7 # Test cases
baDcFEhgJilk
9078563412
896745231
TSNO YRbO0 KNUVIREISYT8 808
HWTAS AS AEOWFL ?'i M AESWALO! Ff NAL VELE1 0010
8967p TYOH NRPGOARMMNI G7698!
return 'Error' # DELETE THIS LINE and start coding here.
# Remember: end all of your functions with a return statement, not a print statement!
8 print (encrypt('abCDefGHIJKLMnopQ'))
9 print (encrypt('ABCdefGHIjkL'))
10 print (encrypt('0123456789'))
11 print (encrypt('123456789'))
12 print (encrypt('Stony Brook University 2022'))
13 print (encrypt("What's a Seawolf? I'm a Seawolf! Fan level 9000!"))
14 print (encrypt('1234 Python programming 4321!'))
Transcribed Image Text:Complete the function encrypt, which takes an unencrypted, plaintext message called plaintext and encrypts it according to the following algorithm. The function then returns the encrypted ciphertext message. 1. Using a for-loop, swap the character at each even-indexed position with the one to its right. (Examples: abcdefg becomes badcfe; abcdefg becomes badcfeg) You'll have to carefully accomodate for even-lengthed and odd-lengthed strings. 2. Then, using another for-loop, replace every uppercase letter with its lowercase equivalent, and replace every lowercase letter with its uppercase equivalent. 3. (May be combined with the loop in the previous step in the code.) Except for the character o, replace each digit character with 10 minus that digit. (Examples: 2 becomes 8, 9 becomes 1.) Hint: use ord and/or chr and/or str and/or int instead of a 10-way if- statement! Examples: Function Call encrypt('abCDefGHIJKLMnopQ') encrypt('ABCdefGHIjkL') encrypt('0123456789') encrypt('123456789') encrypt('Stony Brook University 2022') encrypt ("What's a Seawolf? I'm a Seawolf! Fan level 9000!") encrypt('1234 Python programming 4321!') [ ] 1 import string 2 3 def encrypt (pla text): 4 5 Return Value BAdcFEhgJilkNmPOq 6 7 # Test cases baDcFEhgJilk 9078563412 896745231 TSNO YRbO0 KNUVIREISYT8 808 HWTAS AS AEOWFL ?'i M AESWALO! Ff NAL VELE1 0010 8967p TYOH NRPGOARMMNI G7698! return 'Error' # DELETE THIS LINE and start coding here. # Remember: end all of your functions with a return statement, not a print statement! 8 print (encrypt('abCDefGHIJKLMnopQ')) 9 print (encrypt('ABCdefGHIjkL')) 10 print (encrypt('0123456789')) 11 print (encrypt('123456789')) 12 print (encrypt('Stony Brook University 2022')) 13 print (encrypt("What's a Seawolf? I'm a Seawolf! Fan level 9000!")) 14 print (encrypt('1234 Python programming 4321!'))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education