Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A Caesar cipher is a simple monoalphabetic substitution cipherthat substitutes a

ID: 3609542 • Letter: A

Question

A Caesar cipher is a simple monoalphabetic substitution cipherthat substitutes a character three letters further down thealphabet for the current letter. For example, a becomes d, bbecomes e, c becomes f, etc. So a message like ATTACK AT DAWN is enciphered as DWWDFN DW GDZQ. Write a Java method that takes as input a String object andreturns a String object enciphered using a Caesar cipher. A Caesar cipher is a simple monoalphabetic substitution cipherthat substitutes a character three letters further down thealphabet for the current letter. For example, a becomes d, bbecomes e, c becomes f, etc. So a message like ATTACK AT DAWN is enciphered as DWWDFN DW GDZQ. Write a Java method that takes as input a String object andreturns a String object enciphered using a Caesar cipher.

Explanation / Answer

this program is case sensitive!!!!

public class encryption
{
public static void main(String [] args)
{
String [] alpha = {"A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L"
   , "M", "N", "O", "P", "Q", "R","S", "T", "U", "V", "W", "X"
   , "Y", "Z", };

System.out.println("Please entermessage to encrypt:");
String text = Console.readString();

System.out.println("Please enter numberof characters to be shifted:");
int moves = Console.readInt();   

String convertedText = "";

for(int i = 0; i < text.length();i++)
{
convertedText =convertedText + shift(moves, alpha, text.substring(i, i + 1));
}

System.out.println();
System.out.println("The encryptedmessage is: " + convertedText);
}

public static String shift (int x, String[] arr,String a)
{
String convert = "";
for(int i = 0; i < arr.length;i++)
{
if(a.equals(arr[i]))
{
convert =convert + arr[i + x];
break;
}
}
return convert;
}


}
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote