• Post Reply Bookmark Topic Watch Topic
  • New Topic

Decrypting an encrypted code  RSS feed

 
Kris Davenport
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

In order to do such encryption and decryption, you need to know what the algorithm is. I think the question tells us that already.
When you created the algorithm, what was the first thing you were looking for?

I am getting abSbaSaNbR turning into aAAaac, but I may have changed something in your code.

The way you are writing, it sounds as though you were guessing. You can guess 1000000× and make sure the guesses are all different; that way there is a good chance of your getting a correct solution. Or you can think about it and that way get a correct solution first time. And this is going to take a lot of thinking.
As I said, when you worked out the algorithm, what did you look for first?
 
Kris Davenport
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still kind of new at Java. Im confused what do you mean what did i look for first?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget all about the code. Turn your computer off.

Solve those examples by hand. What are you looking for when you do it? Write it down. And what you are looking for has to be simple. Very simple.

Then turn your computer back on and tell us what you did.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!