Question

IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption...

IN PYTHON

Implement a function easyCrypto() that takes as input a string and prints its encryption defined as follows: Every character at an odd position i in the alphabet will be encrypted with the character at position i + 1, and every character at an even position i will be encrypted with the character at position i - 1. In other words, ‘a’ is encrypted with ‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’, with ‘c’, and so on. Lowercase characters should remain lowercase and upercase characters should remain uppercase.

>>> easyCrypto('abc')

'bad'

>>> easyCrypto('zoo')

'ypp'

>>> easyCrypto('Zoo')

'Ypp'

>>> easyCrypto('ToDay')

'SpCbz'

>>>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note:- The output which is provided by you does not match from the give encryption algorithm. so if you have any queries then comment below.

def easyCrypto(s):
new_str=""
for i in range(len(s)):
if i%2==0:
new_str+=chr(ord(s[i])-1)
else:
new_str+=chr(ord(s[i])+1)
return new_str
  
s=input("Enter string: ")
print(easyCrypto(s))

Add a comment
Know the answer?
Add Answer to:
IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java method that takes a String as its input and prints on the first...

    Write a Java method that takes a String as its input and prints on the first line the odd characters (1st, 3rd, etc) and on the second line the even characters (2nd, 4th, etc).

  • python3.x Write a function print_letter_count(word) that takes a string as a parameter and prints each unique...

    python3.x Write a function print_letter_count(word) that takes a string as a parameter and prints each unique character (in alphabetical order and lowercase) together with their frequency. For example: consider the following word: Programming The characters are: 1 x p, 2 x r, 1 x o, 2 x g, 1 x a, 2 x m, 1 x i and 1 x n. The output would be: a: 1 g: 2 i: 1 m: 2 n: 1 o: 1 p: 1 r:...

  • Write a static method called printWithSpaces that takes a String as its parameter and prints the...

    Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...

  • 2) Write a function stringManip that takes in a character string and returns a character string...

    2) Write a function stringManip that takes in a character string and returns a character string following these rules: a) any vowel (a, e, i, o, u) is replaced by the character '&' b) any numeric character has 1 added to it (if it was 9, it becomes O instead) (str2num() is useful here) c) all lowercase characters become uppercase d) replace the final character with '!' e) append the length of the string before this step to the end...

  • Define a Python function named getResponse() that takes a string as its only argument and returns...

    Define a Python function named getResponse() that takes a string as its only argument and returns a new string. If the argument ends with a question mark and has an even number of characters, the function should return the string "Yes". If the argument ends with a question mark and contains an odd number of characters, the function should return the string "No". If the argument ends with an exclamation point, the function should return the string "Wow". Otherwise, the...

  • In python Exercise 4 (graded) Write a function "passValidate" that takes a string "s" and checks...

    In python Exercise 4 (graded) Write a function "passValidate" that takes a string "s" and checks the validity of string as a password Validation Rules: At least 1 lowercase letter between [a-z] and 1 upper case letter between [A-Z]. At least 1 number between [0-9 At least 1 character from [$#@]. Minimum length 6 characters. Maximum length 16 characters. CS103-Lab 13 Page 3 of 3 Sample Input: s"Uab@2762" Sample Output: True

  • i need python code, thank you very much! characters) and prints ) 3. Write function, smallestCharacterLargerThan(keyChar,...

    i need python code, thank you very much! characters) and prints ) 3. Write function, smallestCharacterLargerThan(keyChar, inputString) that takes as input key character, keyChar, and a string of one or more letters (and no other the "smallest" character in the string that is larger than keyChar, where one character is smaller than another if it occurs earlier in the alphabet (thus 'C is smaller than 'y' and both are larger than 'B') and 2) the index of the final occurrence...

  • PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...

    PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...

  • C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher....

    C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher. cipher_sub (a, b, c, d) a is the string that has the data that will be encrypted or decrypted b is the string that has the result of the encrypt/decrypt c is the code string used for our substitution cipher (27 entries plus '\0' character) d is an integer that will pass two constants defined as ENC (encrypt) or DEC (decrypt) --> The function...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT