I want to create a java program that can be encrypt-decrypt alphabet from characters . Which is the shifting of the alphabet is starting from the the first character to increase 4 and 5 increased in the second character, increasing 6 at the third character, and so on..
Then when one of the characters increasement is more than the ascii code of 'z', that character will decrease from the variable i from the loop. (Sorry my english isn't good enough)
This is the output of the program that i want:
Encryption:
Plain text: "abcz"
Cipher text: "egiz"

What's wrong with my code? It won't work. Specially in the decryption . Please help me...

March 8th, 2014, 10:53 AM

Norm

Re: [HELP] Encryption - Decryption alphabet

Can you copy the console from when the program executed that shows what the problem is?
For testing and debugging use the shortest input String that shows the problem. That will make tracing the code's execution flow easier.
Try debugging the code by adding some println statements that shows the values of variables as their values are set and changed.

March 8th, 2014, 09:17 PM

noobies

Re: [HELP] Encryption - Decryption alphabet

This is the example when my program executed, and it's wrong in the decryption.

You should be able to look at the ciphered text, egiwsr, the resulting decrypted text, abcpki, (which should be abczwi) and then inspect your code to determine why the resulting decryption is incorrect, just as I did for you above.

March 9th, 2014, 06:37 AM

noobies

Re: [HELP] Encryption - Decryption alphabet

Okay, I'll try here.
And when I'm stuck I'll ask again if you don't mind :)

March 9th, 2014, 08:10 PM

noobies

Re: [HELP] Encryption - Decryption alphabet

I'm stuck and I've found this methodology to complete my codes. But, what and where I should type my code here? :/

The output will be:
The "abczzzzzzz" will be encrypted to egidddddd, then "egiddddd" will be decrypted into abczzzz.
BUT when I input "qwerty" it will encrypt "uaky^c". When I input "uak^y" it'll decrypt "qwer^y".
Why the non alpahabetical character still pop out? And what going on with my decryption?
any suggest? I'm trully stuck here -_-

March 10th, 2014, 02:37 AM

GregBrannon

Re: [HELP] Encryption - Decryption alphabet

The encrypt/decrypt algorithm must correctly handle the ends of the alphabet. When a character less than 'a' is needed, the algorithm must wrap to 'z' and then continue backwards from there. When a letter greater than 'z' is needed, the algorithm must wrap to 'a' and continue from there. You can accomplish this using a combination of if statements and the % operator.

March 10th, 2014, 11:44 PM

noobies

Re: [HELP] Encryption - Decryption alphabet

Quote:

Originally Posted by GregBrannon

The encrypt/decrypt algorithm must correctly handle the ends of the alphabet. When a character less than 'a' is needed, the algorithm must wrap to 'z' and then continue backwards from there. When a letter greater than 'z' is needed, the algorithm must wrap to 'a' and continue from there. You can accomplish this using a combination of if statements and the % operator.