Question: ***** don't use handwriting *************** Q1: Describe the code ? Q2: What are the difficulties that we may face when writing these codes? import java.util.*;

***** don't use handwriting ***************

Q1: Describe the code ? Q2: What are the difficulties that we may face when writing these codes?

import java.util.*;

//Class that Applies Caesar Technique class Caesarr { //Instance variables private String plainText; private int key; //Default Constructor public Caesarr() { //Initializing variables to default values plainText = ""; key=0; } //Overloaded Constructor public Caesarr(String txt, int k) { //Initializing variables to default values plainText = txt; key = k; } //Method that encrypts the text public void encrypt() { int move; //Converting to upper case String str = plainText.toUpperCase(); System.out.print(" Encrypted Text: "); //Iterating over each character for(int i=0; i= 65 && (int)(str.charAt(i)) <= 90) { //Checking boundary if( ((int)(str.charAt(i)) + key) > 90) { //Calculating moving index move = ((int)(str.charAt(i)) + key) - 90 + 65 - 1; } else { //Calculating moving index move = ((int)(str.charAt(i)) + key); } //Printing character System.out.print((char)(move)); } else { //Printing normal characters System.out.print(str.charAt(i)); } } System.out.println(" "); } }

//Driver class class CaesarCipherDemo { //Main method public static void main(String[] args) { //Scanner object Scanner reader = new Scanner(System.in); //Reading Plain text from user System.out.print(" Enter Plain Text: "); String plainText = reader.nextLine(); System.out.print(" Enter Key: "); int key = reader.nextInt(); //Creating Caesar Cipher object Caesarr obj = new Caesarr(plainText, key); //Calling method obj.encrypt(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!