Mathew Mintalm wrote:wanted to create Java applet with Cezar cipher
It is Caesar cypher (not Cezar cypher)
Mathew Mintalm wrote:encryption works as it should, but decryption doesn't.
Well, why should decryption work? You've wrote a method encryptDecrypt which only encrypts a character array. It won't decrypt it. So, no matter whatever input you give to it (encrypted, non-encrypted, double encrypted or whatever), it will further encrypt it.
Please write one method for encryption and another for decryption (or at least keep some way - say a boolean parameter - to understand the method whether it should do encryption or decryption - just in case you want to do it with only one method. you'll have to write decryption code anyway).
So, please write code for decryption, and let us know if you face any issues.
Not happy about that: you have got a side-effect that you are changing the chars array. I suggest you use the clone() method to take a copy of that, as a local variable. Note clone() on an array gives you a “shallow” clone, so it is more difficult to use for a char. This version maintains the original array unchanged.
Also: don’t mix tabs and spaces for indenting: you are best off using spaces only. Don’t routinely double-space lines in code; they are not easier to read.
You don’t need to get the char out of an array. If you have index, such that a = 0 and z = 25, you can simply writeThat will of course give you capital letters only, and will not work for spaces or numbers of punctuation.