COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Queues My Queue Program
QueueInterface.java
MyArrayListQueue.java
MyArrayQueue.java
MyQueueProjectClient.java
EmptyQueueException.java
FullQueueException.java
Repeating Key Program



Caesar Cipher Repeating Key Program


Description

This program uses the Caesar Cipher with repeating key algorithm to encrypt a message.

The keys are organized with a queue data structure.

Use Queue interface and LinkedList class in Java Collections to create the queue.

Associated Concepts:

Queue

Java Collections Framework

Algorithm:

main method:

Create a String message with the hard-coded values.

Create an array with the hard-coded integers as keys.

Call encrypt() method and print the returned string.


encrypt method definition:

Create a queue using Queue interface and LinkedList class in Java Collections Framework.

Load the keys in the array into the queue.

Declare a String variable to store the result.

In a loop:

Remove the front key in the queue.

Retrieve each character in the original message.

Encrypt the character with the key.

Add the encrypted character to the result.

Add the key to the rear of the queue.

After the loop ended, return the result.

Source Code