Hello I have been forced by my maths teacher to create website for competition about promoting mathematics.

I chose mathematics in IT/programming. I'm presenting some of my own experience, especially in android game development.

But I wanted to include something easier as well, and created section about cryptology, and wanted to create

Java applet with Cezar cipher

And I have problem, encryption works as it should, but decryption doesn't.

Thats how I understand it:

(sorry for polish description in gif above)

1. type the alphabet

2. Move every character in right direction (based on key, in this case its 3)

3. Put last 3 chars at begining.

--------------------------------------------

I'm using those formulas to encrypt/decrypt

n - number of latter we want to encrypt/decrypt

k - number of movement (in our case 3)

x - number of chars in our alphabet (26 in our case)

------------------------------------------

So I created following code, but as I mentioned it seems to work only in one way (encrypt for example key 3, but decryption gives wrong values for example for key -3)

I will be glad if someone might help me correct it, thanks!