Question: Please add detailed comments in the following both codes and submit the new code. Code 1 class CaesarCipher { public static void main(String args[]) {
Please add detailed comments in the following both codes and submit the new code.
Code 1
|
Code 2
| import java.io.*; import java.util.*; public class Solution { //to keep track of index public static final String alpha = "abcdefghijklmnopqrstuvwxyz"; publicstaticStringencrypt(Stringmessage,intshiftKey) { message = message.toLowerCase(); String cipherText = ""; for (int ii = 0; ii < message.length(); ii++) { int charPosition = aplha.indexOf(message.charAt(ii)); int keyVal = (shiftKey + charPosition) % 26; char replaceVal = aplha.charAt(keyVal); cipherText += replaceVal; } return cipherText; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String message = new String(); int key = 0; System.out.print("Enter the String for Encryption:"); message = sc.next(); System.out.println(" Enter Shift Key:"); key = sc.nextInt(); System.out.println(" Encrpyted msg:" + encrypt(message, key)); } //main method ends } //Solution Class End |
Step by Step Solution
3.48 Rating (161 Votes )
There are 3 Steps involved in it
Adding the detailed comments to the following code Code 1 Implementing the Caesar Cypher encryption technique is the aim of Code 1 With the Caesar Cypher every letter in the plaintext is changed by a ... View full answer
Get step-by-step solutions from verified subject matter experts
