Mirror Encrypt:
a -- z b -- y c -- x d -- w ............... y -- b z -- a
A -- Z B --- Y C -- X D -- W ................ Y -- B Z -- A
EX:- abcd ==> zyxw
AnT ==> ZmG
Ternary or conditional Operator
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class MirrorString{ public static void main(String[] args){ String str = "codeheist"; System.out.println(mirrorEncrypt(str)); } public static String mirrorEncrypt(String str){ String ans = ""; for(int i=0; i<str.length(); i++){ char ch = str.charAt(i); ans += Character.isUpperCase(ch) ? (char)('Z'+'A'-ch) : (char)('z'+'a'-ch); } return ans; } } |
Python
def mirrorEncrypt(input_str): ans = "" for char in input_str: if char.isupper(): ans += chr ( 65 + 90 - ord ( char ) ) else: ans += chr ( 97 + 122 -ord ( char )) return ans input_str = "codeheist" print(mirrorEncrypt(input_str)) |