Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program to encode or decode a message using a Caesar Shift. History of the Caesar Shift Decoder ring Publin Domain The first documented

Write a program to encode or decode a message using a Caesar Shift.
History of the Caesar Shift
Decoder ring
Publin Domain
The first documented use of a substitution cipher in military history is attributed to Julius Caesar (around 50 BCE) during the Gaelic Wars. He sent a coded message to Cicero (who was about to surrender) by substituting Greek letters for Roman letters and later utilizing a substitution cipher that became known as the Caesar Shift. Did you own a secret decoder ring or disk as a child? If so, you have probably used the Caesar Shift. So, when you write your program for this assignment, be careful to whom you send coded messages. With a few lines of Java, any Caesar Shift can be broken, and your secrets revealed.
Getting started
Read the Background section below to understand the Caesar Shift algorithm.
Read all the specifications and create a plan before starting to write your code.
Make sure you understand the difference between a static method, which you call using a class name, and an instance method, which you call using an object.
Create a new project named 09.07 Caesar Shift Cipher in the Mod09 Assignments folder.
Create three new classes called Encryption, Decryption and CaesarTester in the newly created project.
Part 1: CaesarTester
julius Caesar
Public Domain
Provide a menu to allow the user to choose between encryption and decryption. After a message is processed, allow the user to continue entering more messages until the user decides to exit the program.
Declare the shift key as a class variable. Ask the user to input a shift key value from 0-25. Ensure the input is valid.
Ask the user to input a plaintext message.
Declare the alphabet as a class constant.
Part 2: Encryption
Write a static method to generate the cipher alphabet based on the shift key.
Display the alphabet and cipher alphabet on the screen.
Write a static method to encrypt the plaintext message and return the result.
Display the encrypted message for the user to view.
Part 3: Decryption
Write a static method to generate the decipher alphabet based on the shift key.
Display the alphabet and the decipher alphabet on the screen.
Write a static method to decrypt the plaintext message and return the result.
Display the decrypted message for the user to view.
Background: The Caesar Shift
The Caesar Shift cipher is a simple encryption technique based on substitution. In this example, a shift of three was chosen as the key. Each letter in a plaintext message is replaced by the letter three positions further down the alphabet. For example, with a Caesar Shift of three, the letter A in the original message is substituted with the letter D in the cipher message.
Caesar Shift of thre
Public Domain
Can you decode the message shown?
FRPSXWHU VFLHQFH URFNV
The Caesar Shift does not seem very secure, but keep in mind that most of Caesar's adversaries were illiterate. As long as the generals could decode the messages, security was maintained. However, Caesar apparently had more sophisticated encryption techniques when dealing with his political enemies.
A cipher utilizes an algorithm and a key, which specify the exact details of how to encrypt a message. The Caesar Shift algorithm designates which letter in a cipher alphabet to substitute in the plaintext alphabet. For example, if the consecutive letters of the alphabet (x) are represented by the integers 025(e.g., a =0, b =1, z =25), the encryption (En) or decryption (Dn) of a letter x by a shift n can be calculated as follows:
En(x)=(x + n)
En(x)=(x + n)26
Dn(x)=(x n)
Dn(x)=(x n)+26if 0<= x + n <26
if x + n >=26
if 0<= x n <26
if x n <0
Hint: The modulus operator is very helpful for keeping numbers within a range such as 0 to 25.
Writing a program to perform the Caesar Shift substitution cipher is fairly simple. Determine the identity of each consecutive letter in the plaintext message and substitute the corresponding shifted letter in the cipher alphabet. Decrypting can be done in reverse.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions