Question #242648

Give a string writen a program to mirror the characters of the string in alphabetical order to create a secret message

Expert's answer

def cipher(s):
    res = ''
    ia = ord('a')
    iz = ord('z')
    iA = ord('A')
    iZ = ord('Z')
    for ch in s:
        i = ord(ch)
        if ia <= i <= iz:
            res += chr(iz -(i-ia))
        elif iA <= i <= iZ:
            res += chr(iZ -(i-iA))
        else:
            res += ch
    return res

def main():
    line = input('Enter a string - ')
    secret = cipher(line)
    print('Secret message is', secret)

if __name__== '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS