Answer:
The program written in python is as follows;
import string
def easyCrypto(inputstring):
for i in range(len(inputstring)):
try:
ind = string.ascii_lowercase.index(inputstring[i])
pos = ind+1
if pos%2 == 0:
print(string.ascii_lowercase[ind-1],end="")
else:
print(string.ascii_lowercase[ind+1],end="")
except:
ind = string.ascii_uppercase.index(inputstring[i])
pos = ind+1
if pos%2 == 0:
print(string.ascii_uppercase[ind-1],end="")
else:
print(string.ascii_uppercase[ind+1],end="")
anystring = input("Enter a string: ")
easyCrypto(anystring)
Explanation:
The first line imports the string module into the program
import string
The functipn easyCrypto() starts here
def easyCrypto(inputstring):
This line iterates through each character in the input string
for i in range(len(inputstring)):
The try except handles the error in the program
try:
This line gets the index of the current character (lower case)
ind = string.ascii_lowercase.index(inputstring[i])
This line adds 1 to the index
pos = ind+1
This line checks if the character is at even position
if pos%2 == 0:
If yes, it returns the alphabet before it
print(string.ascii_lowercase[ind-1],end="")
else:
It returns the alphabet after it, if otherwise
print(string.ascii_lowercase[ind+1],end="")
The except block does the same thing as the try block, but it handles uppercase letters
<em> except:
</em>
<em> ind = string.ascii_uppercase.index(inputstring[i])
</em>
<em> pos = ind+1
</em>
<em> if pos%2 == 0:
</em>
<em> print(string.ascii_uppercase[ind-1],end="")
</em>
<em> else:
</em>
<em> print(string.ascii_uppercase[ind+1],end="")
</em>
<em />
The main starts here
This line prompts user for input
anystring = input("Enter a string: ")
This line calls the easyCrypto() function
easyCrypto(anystring)