Mirror Cipher

Published by Mubashir Hassan in

In Mirror Cipher, encoding is done by switching message characters with its mirror opposite character of the key.

Create a function that takes two arguments; a message and an optional key, and return the encoded message.

There are some variations on the rules of encipherment. One version of the cipher rules are outlined below:

message = "Mubashir Hassan"
key = "edabitisamazing"

mirrorCipher(message, key) ➞ "tuzishar hissid"

Step 1: Replace all characters of the given message with mirror character in the key:

M = t
// "t" is the mirror character of "m".
// (five characters from the left and right end respectively)

u = u
// "u" is not part of the key.

b = z
// "z" is the mirror character of "b".

a = i, and so on ...

Step 2: Return encoded message in lower case:

"tuzishar hissid"

If optional key is not given, consider the whole alphabet as a default (i.e. key = "abc..z").

Examples

mirrorCipher("Mubashir Hassan", "edabitisamazing") ➞ "tuzishar hissid"

mirrorCipher("Matt MacPherson") ➞ "nzgg nzxksvihlm"

mirrorCipher("Airforce is best", "pilot") ➞ "aorfirce os besp"

Notes

Ignore case of message and key, (e.g. "M" = "m").

Watch a quick demo on how Edabit works.