implementation of the Caesar cipher (Section 5.3 in the textbook), which we discussed in class. Caesar cipher is a simple approach to encoding messages by shifting each letter in a message along the alphabet by a constant amount.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is the implementation of the Caesar cipher (Section
5.3 in the textbook), which we discussed in class. Caesar cipher is a simple approach to
encoding messages by shifting each letter in a message along the alphabet by a
constant amount.
Your code will be similar to Listing 5.1, but you must use CircularArrayQueue.java
instead of the Java API queue.

//5.1

import java.util.*;
public class Codes {
   public static void main(String[] args) {
       int[] key = {5, 12, -3, 8, -9, 4, 10};
       Integer keyValue;
       String encoded = "", decoded = "";
       String message = "All programmer are playwrights and all "+"computers are lausy actors.";
       Queue<Integer> encodingQueue = new LinkedList<Integer>();
       Queue<Integer> decodingQueue = new LinkedList<Integer>();
      
       for (int scan=0; scan < key.length; scan++) {
           encodingQueue.add(key[scan]);
           decodingQueue.add(key[scan]);
       }
       for (int scan=0; scan < message.length(); scan++) {
           keyValue = encodingQueue.remove();
           encoded += (char)(message.charAt(scan)+keyValue);
           encodingQueue.add(keyValue);
       }
       System.out.println("Encoded Message: \n"+encoded+"\n");
       for(int scan=0; scan < encoded.length(); scan++) {
           keyValue = decodingQueue.remove();
           decoded += (char)(encoded.charAt(scan)-keyValue);
           decodingQueue.add(keyValue);
       }
       System.out.println("Decoded Message:\n"+decoded);
   }
}

//CircularArrayQueue

package jsjf;
package jsjf.exceptions.*;
public class CircularArrayQueue<T> implements QueueADT<T>{
   private final static int DEFAULT_CAPACITY = 100;
   private int front, rear, count;
   private T[] queue;
   public CircularArrayQueue(int initialCapacity) {
       front=rear=count=0;
       queue=(T[])(new Object[initialCapacity]);
   }
   public CircularArrayQueue() {
       this(DEFAULT_CAPACITY);
   }
}

//QueueADT

package jsjf;
public interface QueueADT<T> {
   public void enqueue(T element);
   public T dequeue();
   public T first();
   public boolean isEmpty();
   public int size();
   public String toString;

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education