posted 10 years ago
Hey everyone!
I need some help! Here is my assignment.
Alphabet Run Encryption - For this challenge you will be decoding a message.
Using the Java language, create the function AlphabetRunEncryption(str) read the str parameter being passed which will be an encrypted string and your program should output the original decrypted string. The encryption being used is the following: For every character i in str 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. So str may be something like the encrypted string just written, and your program should decrypt it and output the original message. The input string will only contain lowercase characters (a...z). There are also three important rules to this encryption based on specific character sequences. 1) If the original string contains only one letter between two chosen characters, such as the string ac then this would be encrypted as bR with R standing for what direction in the alphabet to go in determining the original characters. The encrypted string bR represents ac but the encrypted string bL represents ca (R = right, L = left). 2) If the original string contains zero letters between two chosen characters, such as the string ab then this would be encrypted as abS, with S representing the fact that no decryption is needed on the two letters preceding S. For example, if the original string were aba then the encryption would be abSbaS, but be careful because decrypting this you get abba, but the actual original string is aba. 3) If the original string contains a repeat of letters, such as the string acc then this would be encrypted as bRcN, with N representing the fact that no change in characters occurred on the character preceding N. The input string will never only be composed of repeated characters.
Correct Sample Output
Input = "bcdefghijklmnopqrstN"Output = "att"
Input = "abSbaSaNbR"Output = "abaac"
Here is my code....
My problem is that when I run it with the selected
I get the correct output of att, however when I switch it and run it as
instead of the output being abaac i get abaaac. Im about to rack my brain on this one. I know that if I change my code of
to
and remove the second translation and run it by switching the test from test i to test ii, I get the correct output for the "abaac" but then I lose a t on the "att" and it only displays as "at". What am I missing or what am I doing wrong?!?! Any help is greatly appreciated!!!