Please help with a python script that can do the following. implement a function
ID: 673993 • Letter: P
Question
Please help with a python script that can do the following.
implement a function easyCrypto() that takes a inpit as a string and prints tis encription 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' woth 'd', 'd' woth 'c', and so on. Lowercase characters should remain lowercase, and uppercase characters should remain uppercase.
>>>easyCrypto('abc')
bad
>>>easyCrypto('zoo')
YPP
Explanation / Answer
def easyCrypto(s):
n=len(s)
for i in range(0,n):
if(s[i] >= 'a' and s[i] <= 'z'):
if(i%2 == 0):
c = ord('a') + ((ord(s[i]) - ord('a') + 1)%26)
print(chr(c))
else:
c = ord('a') + ((ord(s[i]) - ord('a') - 1)%26)
print(chr(c))
else:
if(i%2 == 0):
c = ord('A') + ((ord(s[i]) - ord('A') + 1)%26)
print(chr(c))
else:
c = ord('A') + ((ord(s[i]) - ord('A') - 1)%26)
print(chr(c))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.