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...


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<br>The user will enter two strings one after the other, the first will be the text to encrypt, and the second will be<br>the key used to encrypt it.<br>Example:<br>Hello World<br>udd<br>Constraints<br>0<=len(text)<=1000 0<=len(key)<=1000 len(key) can be greater than len(text)<br>Output Format<br>The program should print out the encrypted text.<br>Example:<br>Kbiol|Zlooa<br>Sample Input 0<br>Hello World<br>udd<br>Sample Output 0<br>Kbiol|Zlooa<br>Sample Input 1<br>abracadabra<br>uu<br>Sample Output 1<br>cdtcecfcdtc<br>

Extracted 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<><=1000><><=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 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="">
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here