I need help in encryption/decryption in java I wanna encrypt and decrypt in main way for example change 'a' to 'c' and 'b' to 'g' and etc.java how can i do it?
Asked
Active
Viewed 109 times
-4
-
2Possible duplicate of [Simple caesar cipher in java](https://stackoverflow.com/questions/1821545/simple-caesar-cipher-in-java) – snipsnipsnip Nov 17 '18 at 09:12
1 Answers
0
You can cast the chars to ints and add a certain value to the int, then cast back to char. For example,
System.out.println((char)((int)’a’+2));
Would produce ‘c’ from ‘a’. It’s taking advantage of the numerical values chars are represented by. Take a look at a Unicode table.

RiseWithMoon
- 104
- 2
- 8
-
1Java doesn't use ASCII. Take a look at a [Unicode table](http://www.unicode.org/charts/nameslist/index.html). – Tom Blodget Nov 17 '18 at 07:24