Caesar Cipher Program in JavaIt is one of the simplest and most used encryption techniques. In this technique, each letter of the given text is replaced by a letter of some fixed number of positions down the alphabet. For example, with a shift of 1, X would be replaced by Y, Y would become Z, and so on. Julius Caesar was the first one who used it for communicating with his officials. Based on his name, this technique was named as Caesar Cipher technique. An integer value is required to cipher a given text. The integer value is known as shift, which indicates the number of positions each letter of the text has been moved down. We can mathematically represent the encryption of a letter by a shift n in the following way: Encryption phase with shift n = En (x) = (x+n)mod 26 Decryption phase with shift n = Dn (x) = (x-n)mod 26 ExamplesText : ABCDEFGHIJKLMNOPQRSTUVWXYZ Shift : 23 Cipher : XYZABCDEFGHIJKLMNOPQRSTUVW Text : ATTACKATONCE Shift : 4 Cipher : EXXEGOEXSRGI We use the following steps to implement the program for the Caesar Cipher technique:
Let's use the above-discussed steps and implement the code for the Caesar Cipher technique. CaesarCipherExample.java Output:
Next TopicDifference between next() and nextLine()
|