You must write a program that encrypts an input into a string of characters.
For every character i
in the input up to the second to last character, take the i
and i+1
characters and encode them by writing the letters of the alphabet, in order, that range in the same direction between those chosen characters.
For example: if the original string were bo
then it would be encoded as cdefghijklmn
, but if the string were boa
then bo
is encoded as cdefghijklmn
and oa
is encoded as nmlkjihgfedcb
with the final encrypted string being cdefghijklmnnmlkjihgfedcb
.
If the original string contain zero letters between two chosen characters, such as the string ab
then you should encrypt it as aRb
with R
standing for what direction in the alphabet to go in determining the original characters. The encrypted string aRb
represents ab
but the encrypted string aLb
represents ba
(R
= right, L
= left).
If two chosen characters in the original string are the same, such as the string tt
, then you should encrypt it as tZt
with Z
standing for zero letters in between.
Examples:
Input: att
Output: bcdefghijklmnopqrstZt
Input: brep
Output: cdefghijklmnopqqponmlkjihgffghijklmno
Input: Optimizer
Output: oRpqrssrqponmlkjjkllkjjklmnopqrstuvwxyyxwvutsrqponmlkjihgffghijklmnopq
Rules:
- You can write a program or a function.
- Your input may contain uppercase letters, so you need to put them all to lowercase before encrypting.
- You can ignore non-alphabet characters.
- One character length strings are undefined.
- Shortest code in bytes wins!
aabbcfcBBAa
? \$\endgroup\$aZa aRb bZb bRc de ed cRb bZb bLa aZa
without any spaces. \$\endgroup\$aRb
, aa =aZa
\$\endgroup\$a
? \$\endgroup\$