QuestionQuestion

Caesar Cipher Lab

Question 1
You will be deciphering a given message. It is encrypted with a Caesar Cipher that increases by 2 after every 3 characters (including symbol characters, which are not encoded), starting at key = 5. You should save this message to a file using a text editor. Then, your program will prompt the user for the name of the file, decrypt the message stored in the file, and then write the decrypted message to a new file called solution.txt.

A sample message talking about getting 5 points of extra credit appears below:

Htsnyhcdjwlevbah! Pfl zxo afsb dwusb srnsyz!

(We may try other sample messages when we test your program.)

HINTS:
Make sure your key does not exceed 26, the number of letters in the alphabet. Consider using modulo division to help.
Make sure you “roll” around the alphabet correctly. For example, if the input letter is “D” and the key is currently 5, subtracting 5 from D’s code would result in you being 1 before A (64). You should add back the code for the letter Z to roll to the end of the alphabet.
For JavaScript/TypeScript coders: You can convert letters to their numerical equivalent numbers by using String.fromCharCode(…) and String.charCodeAt(…). For example, String.fromCharCode(65) produces ‘A’ and ‘A’.charCodeAt(0) produces 65.
For coders in other languages: You can do math directly with letters, such as ‘D’ – ‘A’.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Scanner;

public class Decoder {

    public static void decodeMessage(String msg) throws Exception{

       String decoded = "";
       int key = 5;
       for(int i=0; i< msg.length(); i++){
            if(i != 0 && i % 3 == 0){
                key += 2;
            }
            int end = 90;
            boolean isValid = false;
            if(msg.charAt(i) >= 65 && msg.charAt(i) <= 90){
                end = 90;
                isValid = true;
            }

            if(msg.charAt(i) >= 97 && msg.charAt(i) <= 122){
                end = 122;
                isValid = true;
            }
            char newChar = msg.charAt(i);

            if(isValid) {...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats