How to apply this python code? def encrypt_text(text, key):     encrypted_text = ''          # insert your code here #               return encrypted_text text = input() key = input() print(encrypt_text(text, key))

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter8: Working With Advanced Functions
Section: Chapter Questions
Problem 4.4CP
icon
Related questions
Question

How to apply this python code?

def encrypt_text(text, key):
    encrypted_text = ''
    
    # insert your code here #
    
    
    return encrypted_text

text = input()
key = input()

print(encrypt_text(text, key))

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.
Transcribed Image Text: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.
Sample Input 0
Hello World
udd
Sample Output 0
Kbiol|Zlooa
Sample Input 1
abracadabra
uu
Sample Output 1
cdtcecfcdtc
Transcribed Image Text: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 2 steps with 1 images

Blurred answer
Knowledge Booster
InputStream
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
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage