4
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!
1I'm not sure I quite get all the rules - what's the expected output for
aabbcfcBBAa? – Sp3000 – 2015-07-22T01:22:09.513Is "ab" encrypted as "aZb"? Is "aa" encrypted as "aZa"? – MtnViewMark – 2015-07-22T01:25:51.363
@Sp3000
aZa aRb bZb bRc de ed cRb bZb bLa aZawithout any spaces. – phase – 2015-07-22T01:27:01.977@MtnViewMark ab =
aRb, aa =aZa– phase – 2015-07-22T01:27:37.367What should the output be for the input
a? – Doorknob – 2015-07-22T02:36:14.937@Doorknob That is undefined, meaning it doesn't matter. – phase – 2015-07-22T02:41:10.850
Does "You can ignore non-alphabet characters." mean that we can expect the input to be letters only or can the input have non-letters and we have to filter them out? – Sp3000 – 2015-07-22T11:49:13.260
shouldn't
cBin @Sp3000's test be encodedcLbnotcRb? – MtnViewMark – 2015-07-22T22:31:25.183@MtnViewMark Yes, I messed up. – phase – 2015-07-22T22:35:24.767
@phase In your question, you wrote that the encrypted string
aLbrepresentsba. This mean that the letters are always ordered alphabetically andcLborbLais invaild. – TheCrypt – 2015-07-26T08:24:08.563