PYTHON3 Complete the given function, encrypt_text that encrypts the variable text using the provided key by applying a modified version of Caesar’s Cipher with the following rules: The key will contain a word made up of the letters ‘u’ and ‘d’. The cipher will use the key to determine the direction of the shift, with a ‘u’ indicating that the character must be shifted upwards while a ‘d’ indicating a downward shift. The number of characters in the key will determine the number of positions to shift. The given text variable will only contain characters from the ASCII table with values between 32 and 126. If the key is invalid (empty string, contains characters other than u and d) or the text is invalid (empty string), no encryption occurs and the function returns the original text. If the text has more characters than the key, the key will loop through again to accommodate the additional text characters. An iterative approach should be used to solve this problem. Brute force solutions will not be accepted.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 9PP
icon
Related questions
Question

PYTHON3

Complete the given function, encrypt_text that encrypts the variable text using the provided key by applying a modified version of Caesar’s Cipher with the following rules:

  • The key will contain a word made up of the letters ‘u’ and ‘d’. The cipher will use the key to determine the direction of the shift, with a ‘u’ indicating that the character must be shifted upwards while a ‘d’ indicating a downward shift. The number of characters in the key will determine the number of positions to shift.

  • The given text variable will only contain characters from the ASCII table with values between 32 and 126.

  • If the key is invalid (empty string, contains characters other than u and d) or the text is invalid (empty string), no encryption occurs and the function returns the original text.

  • If the text has more characters than the key, the key will loop through again to accommodate the additional text characters.

  • An iterative approach should be used to solve this problem. Brute force solutions will not be accepted.

Input Format
The user will enter two strings one after the other, the first will be the text to encrypt, and the second will be
the key used to encrypt it.
Example:
Hello World
udd
Constraints
0<=len(text)<=1000 0<=len(key)<=1000 len(key) can be greater than len(text)
Output Format
The program should print out the encrypted text.
Example:
Kbiol|Zlooa
Sample Input 0
Hello World
udd
Sample Output 0
Kbiol|Zlooa
Sample Input 1
abracadabra
uu
Sample Output 1
cdtcecfcdtc
Transcribed Image Text:Input Format The user will enter two strings one after the other, the first will be the text to encrypt, and the second will be the key used to encrypt it. Example: Hello World udd Constraints 0<=len(text)<=1000 0<=len(key)<=1000 len(key) can be greater than len(text) Output Format The program should print out the encrypted text. Example: Kbiol|Zlooa Sample Input 0 Hello World udd Sample Output 0 Kbiol|Zlooa Sample Input 1 abracadabra uu Sample Output 1 cdtcecfcdtc
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr